Wed, 05 Mar 2014 05:30:36 +0200
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
629
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
641
425b169a82aa
- changed header guards into #pragma once
Santeri Piippo <crimsondusk64@gmail.com>
parents:
629
diff
changeset
|
19 | #pragma once |
629
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include "Main.h" |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "Types.h" |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QRegExp> |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include <QDialog> |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | class LDDocument; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | class Ui_MakePrimUI; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | class PrimitiveCategory; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | struct Primitive |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | { |
642
751a8df42842
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents:
641
diff
changeset
|
30 | QString name, |
751a8df42842
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents:
641
diff
changeset
|
31 | title; |
751a8df42842
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents:
641
diff
changeset
|
32 | PrimitiveCategory* category; |
629
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | }; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | class PrimitiveCategory : public QObject |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | { |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | Q_OBJECT |
642
751a8df42842
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents:
641
diff
changeset
|
38 | PROPERTY (public, QString, name, setName, STOCK_WRITE) |
629
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | public: |
642
751a8df42842
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents:
641
diff
changeset
|
41 | enum RegexType |
629
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | { |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | EFilenameRegex, |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | ETitleRegex |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | }; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | struct RegexEntry |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | { |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | QRegExp regex; |
642
751a8df42842
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents:
641
diff
changeset
|
50 | RegexType type; |
629
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | }; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | QList<RegexEntry> regexes; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | QList<Primitive> prims; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | explicit PrimitiveCategory (QString name, QObject* parent = 0); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | bool isValidToInclude(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | static void loadCategories(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | static void populateCategories(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | }; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | // ============================================================================= |
642
751a8df42842
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents:
641
diff
changeset
|
64 | // |
629
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | // PrimitiveScanner |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | // |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | // Worker object that scans the primitives folder for primitives and |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | // builds an index of them. |
642
751a8df42842
- migrated the codebase to use a simpler PROPERTY macro, arrrrrrrrrrrrrrrrrrrrrgh
Santeri Piippo <crimsondusk64@gmail.com>
parents:
641
diff
changeset
|
69 | // |
629
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | class PrimitiveScanner : public QObject |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | { |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | Q_OBJECT |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | public: |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | explicit PrimitiveScanner (QObject* parent = 0); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | virtual ~PrimitiveScanner(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | static void start(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | public slots: |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | void work(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | signals: |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | void starting (int num); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | void workDone(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | void update (int i); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | private: |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | QList<Primitive> m_prims; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | QStringList m_files; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | int m_i; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | int m_baselen; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | }; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | extern QList<PrimitiveCategory*> g_PrimitiveCategories; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | void loadPrimitives(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | PrimitiveScanner* getActivePrimitiveScanner(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | enum PrimitiveType |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | { |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | Circle, |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | Cylinder, |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | Disc, |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | DiscNeg, |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | Ring, |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | Cone, |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | }; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | // ============================================================================= |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | class PrimitivePrompt : public QDialog |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | { |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | Q_OBJECT |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | public: |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | explicit PrimitivePrompt (QWidget* parent = null, Qt::WindowFlags f = 0); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | virtual ~PrimitivePrompt(); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | Ui_MakePrimUI* ui; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | public slots: |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | void hiResToggled (bool on); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | }; |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | void makeCircle (int segs, int divs, double radius, QList<QLineF>& lines); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | LDDocument* generatePrimitive (PrimitiveType type, int segs, int divs, int num); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | // Gets a primitive by the given specs. If the primitive cannot be found, it will |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | // be automatically generated. |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | LDDocument* getPrimitive (PrimitiveType type, int segs, int divs, int num); |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | |
b75c6cce02e2
- refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | QString radialFileName (PrimitiveType type, int segs, int divs, int num); |