src/primitives.h

changeset 667
31540c1f22ea
parent 611
6679e47b019f
equal deleted inserted replaced
666:c595cfb4791c 667:31540c1f22ea
1 /* 1 /*
2 * LDForge: LDraw parts authoring CAD 2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 Santeri Piippo 3 * Copyright (C) 2013, 2014 Santeri Piippo
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 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 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 7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
17 */ 17 */
18 18
19 #ifndef LDFORGE_PRIMITIVES_H 19 #ifndef LDFORGE_PRIMITIVES_H
20 #define LDFORGE_PRIMITIVES_H 20 #define LDFORGE_PRIMITIVES_H
21 21
22 #include "common.h" 22 #include "main.h"
23 #include "types.h" 23 #include "types.h"
24 #include <QRegExp> 24 #include <QRegExp>
25 #include <QDialog> 25 #include <QDialog>
26 26
27 class LDFile; 27 class LDDocument;
28 class Ui_MakePrimUI; 28 class Ui_MakePrimUI;
29 class PrimitiveCategory; 29 class PrimitiveCategory;
30 struct Primitive 30 struct Primitive
31 { str name, title; 31 {
32 QString name, title;
32 PrimitiveCategory* cat; 33 PrimitiveCategory* cat;
33 }; 34 };
34 35
35 class PrimitiveCategory 36 class PrimitiveCategory : public QObject
36 { PROPERTY (str, name, setName) 37 {
38 Q_OBJECT
39 PROPERTY (public, QString, Name, STR_OPS, STOCK_WRITE)
37 40
38 public: 41 public:
39 enum Type 42 enum ERegexType
40 { Filename, 43 {
41 Title 44 EFilenameRegex,
45 ETitleRegex
42 }; 46 };
43 47
44 struct RegexEntry 48 struct RegexEntry
45 { QRegExp regex; 49 {
46 Type type; 50 QRegExp regex;
51 ERegexType type;
47 }; 52 };
48 53
49 QList<RegexEntry> regexes; 54 QList<RegexEntry> regexes;
50 QList<Primitive> prims; 55 QList<Primitive> prims;
51 static QList<Primitive> uncat; 56
57 explicit PrimitiveCategory (QString name, QObject* parent = 0);
58 bool isValidToInclude();
59
60 static void loadCategories();
61 static void populateCategories();
52 }; 62 };
53 63
54 // ============================================================================= 64 // =============================================================================
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
56 // ============================================================================= 66 // =============================================================================
57 // PrimitiveLister 67 // PrimitiveScanner
58 // 68 //
59 // Worker object that scans the primitives folder for primitives and 69 // Worker object that scans the primitives folder for primitives and
60 // builds an index of them. 70 // builds an index of them.
61 // ============================================================================= 71 // =============================================================================
62 class PrimitiveLister : public QObject 72 class PrimitiveScanner : public QObject
63 { Q_OBJECT 73 {
74 Q_OBJECT
64 75
65 public: 76 public:
66 static void start(); 77 explicit PrimitiveScanner (QObject* parent = 0);
78 virtual ~PrimitiveScanner();
79 static void start();
67 80
68 public slots: 81 public slots:
69 void work(); 82 void work();
70 83
71 signals: 84 signals:
72 void starting (int num); 85 void starting (int num);
73 void workDone(); 86 void workDone();
74 void update (int i); 87 void update (int i);
75 88
76 private: 89 private:
77 QList<Primitive> m_prims; 90 QList<Primitive> m_prims;
91 QStringList m_files;
92 int m_i;
93 int m_baselen;
78 }; 94 };
79 95
80 extern QList<PrimitiveCategory> g_PrimitiveCategories; 96 extern QList<PrimitiveCategory*> g_PrimitiveCategories;
81 97
82 void loadPrimitives(); 98 void loadPrimitives();
83 bool primitiveLoaderBusy(); 99 PrimitiveScanner* getActivePrimitiveScanner();
84 100
85 enum PrimitiveType 101 enum PrimitiveType
86 { Circle, 102 {
103 Circle,
87 Cylinder, 104 Cylinder,
88 Disc, 105 Disc,
89 DiscNeg, 106 DiscNeg,
90 Ring, 107 Ring,
91 Cone, 108 Cone,
92 }; 109 };
93 110
94 // ============================================================================= 111 // =============================================================================
95 class PrimitivePrompt : public QDialog 112 class PrimitivePrompt : public QDialog
96 { Q_OBJECT 113 {
114 Q_OBJECT
97 115
98 public: 116 public:
99 explicit PrimitivePrompt (QWidget* parent = null, Qt::WindowFlags f = 0); 117 explicit PrimitivePrompt (QWidget* parent = null, Qt::WindowFlags f = 0);
100 virtual ~PrimitivePrompt(); 118 virtual ~PrimitivePrompt();
101 Ui_MakePrimUI* ui; 119 Ui_MakePrimUI* ui;
103 public slots: 121 public slots:
104 void hiResToggled (bool on); 122 void hiResToggled (bool on);
105 }; 123 };
106 124
107 void makeCircle (int segs, int divs, double radius, QList<QLineF>& lines); 125 void makeCircle (int segs, int divs, double radius, QList<QLineF>& lines);
108 LDFile* generatePrimitive (PrimitiveType type, int segs, int divs, int num); 126 LDDocument* generatePrimitive (PrimitiveType type, int segs, int divs, int num);
109 127
110 // Gets a primitive by the given specs. If the primitive cannot be found, it will 128 // Gets a primitive by the given specs. If the primitive cannot be found, it will
111 // be automatically generated. 129 // be automatically generated.
112 LDFile* getPrimitive (PrimitiveType type, int segs, int divs, int num); 130 LDDocument* getPrimitive (PrimitiveType type, int segs, int divs, int num);
113 131
114 str radialFileName (PrimitiveType type, int segs, int divs, int num); 132 QString radialFileName (PrimitiveType type, int segs, int divs, int num);
115 133
116 #endif // LDFORGE_PRIMITIVES_H 134 #endif // LDFORGE_PRIMITIVES_H

mercurial