src/primitives.cpp

Tue, 15 Nov 2016 17:40:51 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 15 Nov 2016 17:40:51 +0200
changeset 1048
7b778aa2eff2
parent 1039
f68ebbae4efb
child 1053
2a48c0fff107
permissions
-rw-r--r--

Change "m_" prefix to "_" in members of PartDownloader

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
1014
f0a8ecb6a357 Happy new year 2016!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1013
diff changeset
3 * Copyright (C) 2013 - 2016 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
f68ebbae4efb Fixed compilation.
Teemu Piippo <teemu@hecknology.net>
parents: 1028
diff changeset
19 #include <QApplication>
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QDir>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QRegExp>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QFileDialog>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "ldDocument.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
24 #include "mainwindow.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "primitives.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "miscallenous.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "colors.h"
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents: 952
diff changeset
28 #include "ldpaths.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 988
diff changeset
29 #include "documentmanager.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
31
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
32 PrimitiveManager::PrimitiveManager(QObject* parent) :
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
33 QObject(parent),
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
34 HierarchyElement(parent),
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
35 m_activeScanner(nullptr),
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
36 m_unmatched(nullptr) {}
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
37
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
38
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
39 PrimitiveScanner* PrimitiveManager::activeScanner()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
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
41 return m_activeScanner;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
44
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
45 QString PrimitiveManager::getPrimitivesCfgPath() const
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
46 {
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
47 return qApp->applicationDirPath() + DIRSLASH "prims.cfg";
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
48 }
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
49
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
50
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
51 void PrimitiveManager::loadPrimitives()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 // Try to load prims.cfg
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
54 QFile conf (getPrimitivesCfgPath());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
56 if (not conf.open (QIODevice::ReadOnly))
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 // 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
59 startScan();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
63 while (not conf.atEnd())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 QString line = conf.readLine();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 if (line.endsWith ("\n"))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 line.chop (1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
790
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
70 if (line.endsWith ("\r"))
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
71 line.chop (1);
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
72
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 int space = line.indexOf (" ");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 if (space == -1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 Primitive info;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 info.name = line.left (space);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 info.title = line.mid (space + 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
81 m_primitives << info;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
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
84 populateCategories();
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 print ("%1 primitives loaded.\n", m_primitives.size());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
89
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
90 void PrimitiveManager::startScan()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
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 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
93 {
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 loadCategories();
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 m_activeScanner = new PrimitiveScanner(this);
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 m_activeScanner->work();
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
97 connect(m_activeScanner, &PrimitiveScanner::workDone, this, &PrimitiveManager::scanDone);
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 }
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
99 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
101
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
102 void PrimitiveManager::scanDone()
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
103 {
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
104 if (m_activeScanner)
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
105 {
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
106 m_primitives = m_activeScanner->scannedPrimitives();
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
107 populateCategories();
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
108 print ("%1 primitives scanned", m_primitives.size());
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
109 delete m_activeScanner;
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
110 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
111 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
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
115 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
116 {
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 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
118 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
119
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 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
121 }
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
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
123
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
124 void PrimitiveManager::populateCategories()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 {
791
b1eae3a56eda - sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents: 790
diff changeset
126 loadCategories();
b1eae3a56eda - sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents: 790
diff changeset
127
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
128 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
129 category->primitives.clear();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
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
131 for (Primitive& primitive : m_primitives)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 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
134 primitive.category = nullptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 // 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
137 // 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
138 for (PrimitiveCategory* category : m_categories)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 {
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
140 for (PrimitiveCategory::RegexEntry& entry : category->patterns)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 switch (entry.type)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 {
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
144 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
145 // 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
146 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
147 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148
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
149 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
150 // 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
151 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
152 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 }
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 if (matched)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 {
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
157 primitive.category = category;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161
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
162 // 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
163 if (primitive.category)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 }
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 // If there was a match, add the primitive to the category.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 // 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
169 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
170 primitive.category->primitives << primitive;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 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
172 m_unmatched->primitives << primitive;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 }
791
b1eae3a56eda - sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents: 790
diff changeset
174
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
175 // Sort the categories. Note that we only do this here because we needed the original order for pattern matching.
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
176 qSort (m_categories.begin(), m_categories.end(),
791
b1eae3a56eda - sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents: 790
diff changeset
177 [](PrimitiveCategory* const& a, PrimitiveCategory* const& b) -> bool
b1eae3a56eda - sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents: 790
diff changeset
178 {
b1eae3a56eda - sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents: 790
diff changeset
179 return a->name() < b->name();
b1eae3a56eda - sort primitive categories alphabetically
Santeri Piippo <crimsondusk64@gmail.com>
parents: 790
diff changeset
180 });
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
183
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
184 void PrimitiveManager::loadCategories()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 {
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
186 clearCategories();
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
187 QString path = ":/data/primitive-categories.cfg";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 QFile f (path);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
190 if (not f.open (QIODevice::ReadOnly))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 {
882
2f3cc8e045d5 - fixed compilation on windows
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
192 Critical (format (QObject::tr ("Failed to open primitive categories: %1"), f.errorString()));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195
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
196 PrimitiveCategory* category = nullptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
198 while (not f.atEnd())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 {
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
200 QString line = QString::fromUtf8(f.readLine()).trimmed();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
202 if (line.length() == 0 or line[0] == '#')
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204
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
205 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
206 if (colon == -1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 {
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
208 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
209 {
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 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
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 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
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 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
215 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
216 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217
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
218 category = new PrimitiveCategory (line);
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 else if (category)
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 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
223 PrimitiveCategory::PatternType type = PrimitiveCategory::FilenamePattern;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224
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
225 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
226 {
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 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
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 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
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 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
232 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 {
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
235 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
236 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 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
240 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
241 category->patterns << entry;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 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
244 {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 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
246 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248
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
249 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
250 m_categories << category;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 // Add a category for unmatched primitives.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 // Note: if this function is called the second time, g_unmatched has been
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 // deleted at the beginning of the function and is dangling at this point.
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
255 m_unmatched = new PrimitiveCategory (tr ("Other"));
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
256 m_categories << m_unmatched;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 f.close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
260
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
261 double getRadialPoint(int i, int divs, double(*func)(double))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 {
1026
fb320996cce0 Rename Pi to lowercase pi
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1021
diff changeset
263 return (*func)((i * 2 * pi) / divs);
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
264 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
266
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
267 // TODO: this doesn't really belong here.
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
268 void PrimitiveManager::makeCircle (int segs, int divs, double radius, QList<QLineF>& lines)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 for (int i = 0; i < segs; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 {
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
272 double x0 = radius * getRadialPoint(i, divs, cos);
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
273 double x1 = radius * getRadialPoint(i + 1, divs, cos);
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
274 double z0 = radius * getRadialPoint(i, divs, sin);
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
275 double z1 = radius * getRadialPoint(i + 1, divs, sin);
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
276 lines << QLineF(QPointF(x0, z0), QPointF(x1, z1));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
280
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
281 LDObjectList PrimitiveManager::makePrimitiveBody(const PrimitiveSpec& spec)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 LDObjectList objs;
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
284 QList<int> conditionalLineSegments;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 QList<QLineF> circle;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
287 makeCircle (spec.segments, spec.divisions, 1, circle);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
289 for (int i = 0; i < spec.segments; ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 {
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
291 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
292 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
293 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
294 double z1 = circle[i].y2();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
296 switch (spec.type)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 {
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
298 case Circle:
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 Vertex v0 (x0, 0.0f, z0),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 v1 (x1, 0.0f, z1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
303 LDLine* line (LDSpawn<LDLine>());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 line->setVertex (0, v0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 line->setVertex (1, v1);
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
306 line->setColor (EdgeColor);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 objs << line;
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
308 }
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
309 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310
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
311 case Cylinder:
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
312 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
313 case Cone:
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 double x2, x3, z2, z3;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316 double y0, y1, y2, y3;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
318 if (spec.type == Cylinder)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 x2 = x1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 x3 = x0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 z2 = z1;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 z3 = z0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 y0 = y1 = 0.0f;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 y2 = y3 = 1.0f;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 {
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
330 x2 = x1 * (spec.ringNumber + 1);
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
331 x3 = x0 * (spec.ringNumber + 1);
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
332 z2 = z1 * (spec.ringNumber + 1);
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
333 z3 = z0 * (spec.ringNumber + 1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
335 x0 *= spec.ringNumber;
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
336 x1 *= spec.ringNumber;
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
337 z0 *= spec.ringNumber;
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
338 z1 *= spec.ringNumber;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
340 if (spec.type == Ring)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 y0 = y1 = y2 = y3 = 0.0f;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 y0 = y1 = 1.0f;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 y2 = y3 = 0.0f;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348
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
349 Vertex v0 (x0, y0, z0);
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
350 Vertex v1 (x1, y1, z1);
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
351 Vertex v2 (x2, y2, z2);
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
352 Vertex v3 (x3, y3, z3);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
354 LDQuad* quad (LDSpawn<LDQuad> (v0, v1, v2, v3));
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
355 quad->setColor (MainColor);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
357 if (spec.type == Cylinder)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 quad->invert();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 objs << quad;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
362 if (spec.type == Cylinder or spec.type == Cone)
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
363 conditionalLineSegments << i;
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
364 }
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
365 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366
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
367 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
368 case DiscNegative:
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 double x2, z2;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
372 if (spec.type == Disc)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 x2 = z2 = 0.0f;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 x2 = (x0 >= 0.0f) ? 1.0f : -1.0f;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 z2 = (z0 >= 0.0f) ? 1.0f : -1.0f;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 Vertex v0 (x0, 0.0f, z0),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 v1 (x1, 0.0f, z1),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 v2 (x2, 0.0f, z2);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 // Disc negatives need to go the other way around, otherwise
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 // they'll end up upside-down.
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
386 LDTriangle* seg (LDSpawn<LDTriangle>());
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
387 seg->setColor (MainColor);
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
388 seg->setVertex (spec.type == Disc ? 0 : 2, v0);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 seg->setVertex (1, v1);
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
390 seg->setVertex (spec.type == Disc ? 2 : 0, v2);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 objs << seg;
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
392 }
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
393 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 // 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
398 // end, too.
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
399 if (spec.segments < spec.divisions and not conditionalLineSegments.isEmpty())
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
400 conditionalLineSegments << spec.segments;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401
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
402 for (int i : conditionalLineSegments)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 {
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
404 Vertex v0 (getRadialPoint (i, spec.divisions, cos), 0.0f, getRadialPoint (i, spec.divisions, sin));
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
405 Vertex v1;
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
406 Vertex v2 (getRadialPoint (i + 1, spec.divisions, cos), 0.0f, getRadialPoint (i + 1, spec.divisions, sin));
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
407 Vertex v3 (getRadialPoint (i - 1, spec.divisions, cos), 0.0f, getRadialPoint (i - 1, spec.divisions, sin));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
409 if (spec.type == Cylinder)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
410 {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 v1 = Vertex (v0[X], 1.0f, v0[Z]);
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
412 }
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
413 else if (spec.type == Cone)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 {
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
415 v1 = Vertex (v0[X] * (spec.ringNumber + 1), 0.0f, v0[Z] * (spec.ringNumber + 1));
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
416 v0.setX (v0.x() * spec.ringNumber);
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 662
diff changeset
417 v0.setY (1.0);
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
418 v0.setZ (v0.z() * spec.ringNumber);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
421 LDCondLine* line = (LDSpawn<LDCondLine>());
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
422 line->setColor (EdgeColor);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 line->setVertex (0, v0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 line->setVertex (1, v1);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 line->setVertex (2, v2);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426 line->setVertex (3, v3);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 objs << line;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 return objs;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
433
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
434 QString PrimitiveManager::primitiveTypeName (PrimitiveType type)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 // Not translated as primitives are in English.
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
437 const char* names[] = { "Circle", "Cylinder", "Disc", "Disc Negative", "Ring", "Cone" };
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
438
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
439 if (type >= 0 and type < countof(names))
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
440 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
441 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
442 return "Unknown";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
445
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
446 QString PrimitiveManager::makeRadialFileName(const PrimitiveSpec& spec)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 {
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
448 int numerator = spec.segments;
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
449 int denominator = spec.divisions;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 // Simplify the fractional part, but the denominator must be at least 4.
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
452 simplify (numerator, denominator);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453
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
454 if (denominator < 4)
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 const int factor = 4 / denominator;
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 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
458 denominator *= factor;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 // Compose some general information: prefix, fraction, root, ring number
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
462 QString prefix = (spec.divisions == LowResolution) ? "" : format ("%1/", spec.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
463 QString frac = format ("%1-%2", numerator, denominator);
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
464 static const char* roots[] = { "edge", "cyli", "disc", "ndis", "ring", "con" };
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
465 QString root = roots[spec.type];
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
466 QString numstr = (spec.type == Ring or spec.type == Cone) ? format ("%1", spec.ringNumber) : "";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468 // Truncate the root if necessary (7-16rin4.dat for instance).
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 // However, always keep the root at least 2 characters.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 int extra = (frac.length() + numstr.length() + root.length()) - 8;
966
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
471 root.chop (qBound (0, extra, 2));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473 // Stick them all together and return the result.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474 return prefix + frac + root + numstr + ".dat";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
477
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
478 LDDocument* PrimitiveManager::generatePrimitive(const PrimitiveSpec& spec)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 // 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
481 QString fraction = QString::number ((float) spec.segments / spec.divisions);
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
482 QString name = makeRadialFileName(spec);
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
483 QString description;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
484
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
485 // Ensure that there's decimals, even if they're 0.
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
486 if (fraction.indexOf (".") == -1)
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
487 fraction += ".0";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
488
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
489 if (spec.type == Ring or spec.type == Cone)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 QString spacing =
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
492 (spec.ringNumber < 10) ? " " :
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
493 (spec.ringNumber < 100) ? " " : "";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
495 description = format ("%1 %2%3 x %4", primitiveTypeName (spec.type), spacing, spec.ringNumber, fraction);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
497 else
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
498 description = format ("%1 %2", primitiveTypeName (spec.type), fraction);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500 // Prepend "Hi-Res" if 48/ primitive.
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
501 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
502 description.insert (0, "Hi-Res ");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503
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
504 LDDocument* document = m_window->newDocument();
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
505 document->setDefaultName (name);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507 QString author = APPNAME;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
508 QString license = "";
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
509 bool hires = (spec.divisions == HighResolution);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
510
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
511 if (not m_config->defaultName().isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
512 {
1028
5877e49e9a28 Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1026
diff changeset
513 license = preferredLicenseText();
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
514 author = format ("%1 [%2]", m_config->defaultName(), m_config->defaultUser());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
515 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
517 LDObjectList objs;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518
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
519 objs << LDSpawn<LDComment> (description)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
520 << LDSpawn<LDComment> (format ("Name: %1", name))
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
521 << LDSpawn<LDComment> (format ("Author: %1", author))
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
522 << LDSpawn<LDComment> (format ("!LDRAW_ORG Unofficial_%1Primitive", hires ? "48_" : ""))
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
523 << LDSpawn<LDComment> (license)
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
524 << LDSpawn<LDEmpty>()
988
ac4a2ae54f76 Refactor LDObject API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
525 << LDSpawn<LDBfc> (BfcStatement::CertifyCCW)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
526 << LDSpawn<LDEmpty>();
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
527
979
880d3fe9ac7c Refactor LDDocument's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
528 document->openForEditing();
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
529 document->history()->setIgnoring (false);
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
530 document->addObjects (objs);
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
531 document->addObjects (makePrimitiveBody(spec));
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
532 document->addHistoryStep();
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
533 return document;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
534 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
536
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
537 // Gets a primitive by the given spec. If the primitive cannot be found, it will be automatically generated.
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
538 LDDocument* PrimitiveManager::getPrimitive(const PrimitiveSpec& spec)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 {
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
540 QString name = makeRadialFileName(spec);
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
541 LDDocument* document = m_window->documents()->getDocumentByName (name);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542
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
543 if (document)
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
544 return document;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1018
diff changeset
546 return generatePrimitive(spec);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
547 }
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
548
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
549
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
550 void PrimitiveManager::populateTreeWidget(QTreeWidget* tree, const QString& selectByDefault)
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
551 {
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
552 tree->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
553
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 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
555 {
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 PrimitiveTreeItem* parentItem = new PrimitiveTreeItem (tree, 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
557 parentItem->setText (0, 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
558 QList<QTreeWidgetItem*> subfileItems;
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
559
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
560 for (Primitive& prim : category->primitives)
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
561 {
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
562 PrimitiveTreeItem* item = new PrimitiveTreeItem (parentItem, &prim);
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
563 item->setText (0, format ("%1 - %2", prim.name, prim.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
564 subfileItems << item;
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
565
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
566 // If this primitive is the one the current object points to,
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
567 // select it by default
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
568 if (selectByDefault == prim.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
569 tree->setCurrentItem (item);
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 }
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
571
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
572 tree->addTopLevelItem (parentItem);
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 }
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 }
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
575
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
576
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
577 //
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
578 // ---------------------------------------------------------------------------------------------------------------------
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
579 //
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
580
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
581
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
582 PrimitiveCategory::PrimitiveCategory (QString name, QObject* parent) :
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
583 QObject (parent),
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
584 m_name (name) {}
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
585
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
586
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
587 bool PrimitiveCategory::isValidToInclude()
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
588 {
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
589 return not patterns.isEmpty();
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
590 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
591
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
592
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
593 QString PrimitiveCategory::name() const
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
594 {
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
595 return m_name;
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
596 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
597
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
598
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
599 //
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
600 // ---------------------------------------------------------------------------------------------------------------------
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
601 //
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
602
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
603
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
604 PrimitiveScanner::PrimitiveScanner (PrimitiveManager* parent) :
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
605 QObject(parent),
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
606 HierarchyElement(parent),
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
607 m_manager(parent),
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
608 m_iterator(LDPaths::primitivesDir(), QDirIterator::Subdirectories)
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
609 {
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
610 m_basePathLength = LDPaths::primitivesDir().absolutePath().length();
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
611 print("Scanning primitives...");
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
612 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
613
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
614
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
615 const QList<Primitive>& PrimitiveScanner::scannedPrimitives() const
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
616 {
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
617 return m_prims;
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
618 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
619
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
620
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
621 void PrimitiveScanner::work()
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
622 {
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
623 for (int i = 0; m_iterator.hasNext() and i < 100; ++i)
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
624 {
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
625 QString filename = m_iterator.next();
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
626 QFile file (filename);
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
627
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
628 if (not file.open (QIODevice::ReadOnly))
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
629 continue;
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
630
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
631 Primitive primitive;
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
632 primitive.name = filename.mid (m_basePathLength + 1); // make full path relative
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
633 primitive.name.replace ('/', '\\'); // use DOS backslashes, they're expected
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
634 primitive.category = nullptr;
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
635 QByteArray titledata = file.readLine();
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
636
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
637 if (titledata != QByteArray())
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
638 primitive.title = QString::fromUtf8 (titledata);
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
639
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
640 primitive.title = primitive.title.simplified();
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
641
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
642 if (primitive.title[0] == '0')
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
643 {
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
644 primitive.title.remove (0, 1); // remove 0
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
645 primitive.title = primitive.title.simplified();
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
646 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
647
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
648 m_prims << primitive;
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
649 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
650
1021
f40c792c9334 Replaced GetRecursiveFilenames with QDirIterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1020
diff changeset
651 if (not m_iterator.hasNext())
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
652 {
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
653 // Done with primitives, now save to a config file
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
654 QString path = m_manager->getPrimitivesCfgPath();
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
655 QFile configFile (path);
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
656
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
657 if (configFile.open (QIODevice::WriteOnly | QIODevice::Text))
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
658 {
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
659 for (Primitive& info : m_prims)
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
660 fprint (configFile, "%1 %2\r\n", info.name, info.title);
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
661
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
662 configFile.close();
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
663 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
664 else
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
665 {
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
666 errorPrompt(m_window, format("Couldn't write primitive list %1: %2", path, configFile.errorString()));
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
667 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
668
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
669 emit workDone();
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
670 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
671 else
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
672 {
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
673 // Defer to event loop, pick up the work later
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
674 QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection);
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
675 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
676 }
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
677
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
678
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
679 //
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
680 // ---------------------------------------------------------------------------------------------------------------------
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
681 //
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
682
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
683
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
684 PrimitiveTreeItem::PrimitiveTreeItem (QTreeWidgetItem* parent, Primitive* info) :
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
685 QTreeWidgetItem (parent),
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 m_primitive (info) {}
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
687
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
688
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
689 PrimitiveTreeItem::PrimitiveTreeItem (QTreeWidget* parent, Primitive* info) :
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
690 QTreeWidgetItem (parent),
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
691 m_primitive (info) {}
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
692
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
693
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
694 Primitive* PrimitiveTreeItem::primitive() const
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
695 {
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
696 return m_primitive;
49358df9495b Transformed primitive management into a new class PrimitiveManager that is a member of MainWindow
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
697 }

mercurial