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