| 26 class Model; |
26 class Model; |
| 27 class LDSubfileReference; |
27 class LDSubfileReference; |
| 28 class LDDocument; |
28 class LDDocument; |
| 29 class LDBfc; |
29 class LDBfc; |
| 30 |
30 |
| 31 // |
31 /* |
| 32 // Object type codes. |
32 * Object type codes. |
| 33 // |
33 */ |
| 34 enum LDObjectType |
34 enum LDObjectType |
| 35 { |
35 { |
| 36 SubfileReference, // Object represents a sub-file reference |
36 SubfileReference, // Object represents a sub-file reference |
| 37 Quad, // Object represents a quadrilateral |
37 Quad, // Object represents a quadrilateral |
| 38 Triangle, // Object represents a triangle |
38 Triangle, // Object represents a triangle |
| 46 _End |
46 _End |
| 47 }; |
47 }; |
| 48 |
48 |
| 49 MAKE_ITERABLE_ENUM(LDObjectType) |
49 MAKE_ITERABLE_ENUM(LDObjectType) |
| 50 |
50 |
| 51 // |
51 /* |
| 52 // LDObject |
52 * Represents one line of code in an LDraw model file. |
| 53 // |
53 */ |
| 54 // Base class object for all object types. Each LDObject represents a single line |
|
| 55 // in the LDraw code file. The virtual method getType returns an enumerator |
|
| 56 // which is a token of the object's type. The object can be casted into |
|
| 57 // sub-classes based on this enumerator. |
|
| 58 // |
|
| 59 class LDObject : public QObject |
54 class LDObject : public QObject |
| 60 { |
55 { |
| 61 Q_OBJECT |
56 Q_OBJECT |
| 62 |
57 |
| 63 public: |
58 public: |
| 64 virtual QString asText() const = 0; // This object as LDraw code |
59 virtual QString asText() const = 0; // This object as LDraw code |
| 65 LDColor color() const; |
60 LDColor color() const; |
| 66 virtual LDColor defaultColor() const; // What color does the object default to? |
61 virtual LDColor defaultColor() const; // What color does the object default to? |
| 67 Model* model() const; |
62 Model* model() const; |
| 68 LDPolygon* getPolygon(); |
63 LDPolygon* getPolygon(); |
| 69 virtual void getVertices (QSet<Vertex>& verts) const; |
64 virtual void getVertices (QSet<Vertex>& verts) const; |
| 70 virtual bool hasMatrix() const; // Does this object have a matrix and position? (see LDMatrixObject) |
65 virtual bool hasMatrix() const; // Does this object have a matrix and position? (see LDMatrixObject) |
| 113 LDColor m_color; |
108 LDColor m_color; |
| 114 QColor m_randomColor; |
109 QColor m_randomColor; |
| 115 Vertex m_coords[4]; |
110 Vertex m_coords[4]; |
| 116 }; |
111 }; |
| 117 |
112 |
| 118 // |
113 /* |
| 119 // Common code for objects with matrices. This class is multiple-derived in |
114 * Base class for objects with matrices. |
| 120 // and thus not used directly other than as a common storage point for matrices |
115 */ |
| 121 // and vertices. |
|
| 122 // |
|
| 123 // In 0.1-alpha, there was a separate 'radial' type which had a position and |
|
| 124 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping |
|
| 125 // this class distinct in case I get new extension ideas. :) |
|
| 126 // |
|
| 127 class LDMatrixObject : public LDObject |
116 class LDMatrixObject : public LDObject |
| 128 { |
117 { |
| 129 Vertex m_position; |
118 Vertex m_position; |
| 130 |
119 |
| 131 public: |
120 public: |
| 141 |
130 |
| 142 private: |
131 private: |
| 143 Matrix m_transformationMatrix; |
132 Matrix m_transformationMatrix; |
| 144 }; |
133 }; |
| 145 |
134 |
| 146 // |
135 /* |
| 147 // |
136 * Represents a line in the LDraw file that could not be properly parsed. |
| 148 // Represents a line in the LDraw file that could not be properly parsed. It is |
137 */ |
| 149 // represented by a (!) ERROR in the code view. It exists for the purpose of |
|
| 150 // allowing garbage lines be debugged and corrected within LDForge. |
|
| 151 // |
|
| 152 class LDError : public LDObject |
138 class LDError : public LDObject |
| 153 { |
139 { |
| 154 public: |
140 public: |
| 155 static constexpr LDObjectType SubclassType = LDObjectType::Error; |
141 static constexpr LDObjectType SubclassType = LDObjectType::Error; |
| 156 |
142 |
| 178 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? |
164 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? |
| 179 QString m_contents; // The LDraw code that was being parsed |
165 QString m_contents; // The LDraw code that was being parsed |
| 180 QString m_reason; |
166 QString m_reason; |
| 181 }; |
167 }; |
| 182 |
168 |
| 183 // |
169 /* |
| 184 // |
170 * Represents a 0 BFC statement in the LDraw code. |
| 185 // Represents a 0 BFC statement in the LDraw code. |
171 */ |
| 186 // |
|
| 187 enum class BfcStatement |
172 enum class BfcStatement |
| 188 { |
173 { |
| 189 CertifyCCW, |
174 CertifyCCW, |
| 190 CCW, |
175 CCW, |
| 191 CertifyCW, |
176 CertifyCW, |
| 296 friend class Model; |
277 friend class Model; |
| 297 LDLine (Model* model); |
278 LDLine (Model* model); |
| 298 LDLine (Vertex v1, Vertex v2, Model* model = nullptr); |
279 LDLine (Vertex v1, Vertex v2, Model* model = nullptr); |
| 299 }; |
280 }; |
| 300 |
281 |
| 301 // |
282 /* |
| 302 // LDCondLine |
283 * Represents a single code-5 conditional line. |
| 303 // |
284 */ |
| 304 // Represents a single code-5 conditional line. |
|
| 305 // |
|
| 306 class LDCondLine : public LDLine |
285 class LDCondLine : public LDLine |
| 307 { |
286 { |
| 308 public: |
287 public: |
| 309 static constexpr LDObjectType SubclassType = LDObjectType::CondLine; |
288 static constexpr LDObjectType SubclassType = LDObjectType::CondLine; |
| 310 |
289 |
| 324 friend class Model; |
303 friend class Model; |
| 325 LDCondLine (Model* model); |
304 LDCondLine (Model* model); |
| 326 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); |
305 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); |
| 327 }; |
306 }; |
| 328 |
307 |
| 329 // |
308 /* |
| 330 // LDTriangle |
309 * Represents a single code-3 triangle in the LDraw code file. |
| 331 // |
310 */ |
| 332 // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 |
|
| 333 // and v2 contain the end-points of this triangle. dColor is the color the |
|
| 334 // triangle is colored with. |
|
| 335 // |
|
| 336 class LDTriangle : public LDObject |
311 class LDTriangle : public LDObject |
| 337 { |
312 { |
| 338 public: |
313 public: |
| 339 static constexpr LDObjectType SubclassType = LDObjectType::Triangle; |
314 static constexpr LDObjectType SubclassType = LDObjectType::Triangle; |
| 340 |
315 |
| 353 friend class Model; |
328 friend class Model; |
| 354 LDTriangle (Model* model); |
329 LDTriangle (Model* model); |
| 355 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, Model* model = nullptr); |
330 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, Model* model = nullptr); |
| 356 }; |
331 }; |
| 357 |
332 |
| 358 // |
333 /* |
| 359 // LDQuad |
334 * Represents a single code-4 quadrilateral. |
| 360 // |
335 */ |
| 361 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
|
| 362 // of the quad, dColor is the color used for the quad. |
|
| 363 // |
|
| 364 class LDQuad : public LDObject |
336 class LDQuad : public LDObject |
| 365 { |
337 { |
| 366 public: |
338 public: |
| 367 static constexpr LDObjectType SubclassType = LDObjectType::Quad; |
339 static constexpr LDObjectType SubclassType = LDObjectType::Quad; |
| 368 |
340 |
| 381 friend class Model; |
353 friend class Model; |
| 382 LDQuad (Model* model); |
354 LDQuad (Model* model); |
| 383 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model = nullptr); |
355 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model = nullptr); |
| 384 }; |
356 }; |
| 385 |
357 |
| |
358 /* |
| |
359 * Models a Bézier curve. It is stored as a special comment in the LDraw code file and can be inlined down into line segments. |
| |
360 */ |
| 386 class LDBezierCurve : public LDObject |
361 class LDBezierCurve : public LDObject |
| 387 { |
362 { |
| 388 public: |
363 public: |
| 389 static constexpr LDObjectType SubclassType = LDObjectType::BezierCurve; |
364 static constexpr LDObjectType SubclassType = LDObjectType::BezierCurve; |
| 390 |
365 |