src/primitives.h

changeset 675
450827da2376
parent 674
3d8ab0f89102
parent 629
b75c6cce02e2
child 676
f7f965742fd5
equal deleted inserted replaced
674:3d8ab0f89102 675:450827da2376
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 #ifndef LDFORGE_PRIMITIVES_H
20 #define LDFORGE_PRIMITIVES_H
21
22 #include "main.h"
23 #include "types.h"
24 #include <QRegExp>
25 #include <QDialog>
26
27 class LDDocument;
28 class Ui_MakePrimUI;
29 class PrimitiveCategory;
30 struct Primitive
31 {
32 QString name, title;
33 PrimitiveCategory* cat;
34 };
35
36 class PrimitiveCategory : public QObject
37 {
38 Q_OBJECT
39 PROPERTY (public, QString, Name, STR_OPS, STOCK_WRITE)
40
41 public:
42 enum ERegexType
43 {
44 EFilenameRegex,
45 ETitleRegex
46 };
47
48 struct RegexEntry
49 {
50 QRegExp regex;
51 ERegexType type;
52 };
53
54 QList<RegexEntry> regexes;
55 QList<Primitive> prims;
56
57 explicit PrimitiveCategory (QString name, QObject* parent = 0);
58 bool isValidToInclude();
59
60 static void loadCategories();
61 static void populateCategories();
62 };
63
64 // =============================================================================
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
66 // =============================================================================
67 // PrimitiveScanner
68 //
69 // Worker object that scans the primitives folder for primitives and
70 // builds an index of them.
71 // =============================================================================
72 class PrimitiveScanner : public QObject
73 {
74 Q_OBJECT
75
76 public:
77 explicit PrimitiveScanner (QObject* parent = 0);
78 virtual ~PrimitiveScanner();
79 static void start();
80
81 public slots:
82 void work();
83
84 signals:
85 void starting (int num);
86 void workDone();
87 void update (int i);
88
89 private:
90 QList<Primitive> m_prims;
91 QStringList m_files;
92 int m_i;
93 int m_baselen;
94 };
95
96 extern QList<PrimitiveCategory*> g_PrimitiveCategories;
97
98 void loadPrimitives();
99 PrimitiveScanner* getActivePrimitiveScanner();
100
101 enum PrimitiveType
102 {
103 Circle,
104 Cylinder,
105 Disc,
106 DiscNeg,
107 Ring,
108 Cone,
109 };
110
111 // =============================================================================
112 class PrimitivePrompt : public QDialog
113 {
114 Q_OBJECT
115
116 public:
117 explicit PrimitivePrompt (QWidget* parent = null, Qt::WindowFlags f = 0);
118 virtual ~PrimitivePrompt();
119 Ui_MakePrimUI* ui;
120
121 public slots:
122 void hiResToggled (bool on);
123 };
124
125 void makeCircle (int segs, int divs, double radius, QList<QLineF>& lines);
126 LDDocument* generatePrimitive (PrimitiveType type, int segs, int divs, int num);
127
128 // Gets a primitive by the given specs. If the primitive cannot be found, it will
129 // be automatically generated.
130 LDDocument* getPrimitive (PrimitiveType type, int segs, int divs, int num);
131
132 QString radialFileName (PrimitiveType type, int segs, int divs, int num);
133
134 #endif // LDFORGE_PRIMITIVES_H

mercurial