26 class Model; |
26 class Model; |
27 |
27 |
28 #define LDOBJ(T) \ |
28 #define LDOBJ(T) \ |
29 public: \ |
29 public: \ |
30 static constexpr LDObjectType SubclassType = OBJ_##T; \ |
30 static constexpr LDObjectType SubclassType = OBJ_##T; \ |
31 LD##T (Model* model = nullptr); \ |
|
32 \ |
31 \ |
33 virtual LDObjectType type() const override \ |
32 virtual LDObjectType type() const override \ |
34 { \ |
33 { \ |
35 return OBJ_##T; \ |
34 return OBJ_##T; \ |
36 } \ |
35 } \ |
37 \ |
36 \ |
38 virtual QString asText() const override; \ |
37 virtual QString asText() const override; \ |
39 virtual void invert() override; \ |
38 virtual void invert() override; \ |
|
39 protected: \ |
|
40 friend class Model; \ |
|
41 LD##T (Model* model = nullptr); \ |
40 |
42 |
41 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; } |
43 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; } |
42 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; } |
44 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; } |
43 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } |
45 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } |
44 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
46 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
93 class LDObject : public QObject |
95 class LDObject : public QObject |
94 { |
96 { |
95 Q_OBJECT |
97 Q_OBJECT |
96 |
98 |
97 public: |
99 public: |
98 LDObject (Model* model = nullptr); |
|
99 |
|
100 virtual QString asText() const = 0; // This object as LDraw code |
100 virtual QString asText() const = 0; // This object as LDraw code |
101 LDColor color() const; |
101 LDColor color() const; |
102 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
102 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
103 Model* model() const; |
103 Model* model() const; |
104 LDPolygon* getPolygon(); |
104 LDPolygon* getPolygon(); |
160 class LDMatrixObject : public LDObject |
161 class LDMatrixObject : public LDObject |
161 { |
162 { |
162 Vertex m_position; |
163 Vertex m_position; |
163 |
164 |
164 public: |
165 public: |
165 LDMatrixObject (Model* model = nullptr); |
|
166 LDMatrixObject (const Matrix& transformationMatrix, const Vertex& pos, Model* model = nullptr); |
|
167 |
|
168 const Vertex& position() const; |
166 const Vertex& position() const; |
169 void setCoordinate (const Axis ax, double value); |
167 void setCoordinate (const Axis ax, double value); |
170 void setPosition (const Vertex& a); |
168 void setPosition (const Vertex& a); |
171 void setTransformationMatrix (const Matrix& value); |
169 void setTransformationMatrix (const Matrix& value); |
172 const Matrix& transformationMatrix() const; |
170 const Matrix& transformationMatrix() const; |
173 |
171 |
|
172 protected: |
|
173 LDMatrixObject (Model* model = nullptr); |
|
174 LDMatrixObject (const Matrix& transformationMatrix, const Vertex& pos, Model* model = nullptr); |
|
175 |
174 private: |
176 private: |
175 Matrix m_transformationMatrix; |
177 Matrix m_transformationMatrix; |
176 }; |
178 }; |
177 |
179 |
178 // |
180 // |
189 LDOBJ_UNCOLORED |
191 LDOBJ_UNCOLORED |
190 LDOBJ_SCEMANTIC |
192 LDOBJ_SCEMANTIC |
191 LDOBJ_NO_MATRIX |
193 LDOBJ_NO_MATRIX |
192 |
194 |
193 public: |
195 public: |
194 LDError (QString contents, QString reason, Model* model = nullptr); |
|
195 QString reason() const; |
196 QString reason() const; |
196 QString contents() const; |
197 QString contents() const; |
197 QString fileReferenced() const; |
198 QString fileReferenced() const; |
198 void setFileReferenced (QString value); |
199 void setFileReferenced (QString value); |
199 |
200 |
|
201 protected: |
|
202 LDError (QString contents, QString reason, Model* model = nullptr); |
|
203 |
200 private: |
204 private: |
201 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? |
205 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? |
202 QString m_contents; // The LDraw code that was being parsed |
206 QString m_contents; // The LDraw code that was being parsed |
203 QString m_reason; |
207 QString m_reason; |
204 }; |
208 }; |
268 LDOBJ_UNCOLORED |
274 LDOBJ_UNCOLORED |
269 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } |
275 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } |
270 LDOBJ_NO_MATRIX |
276 LDOBJ_NO_MATRIX |
271 |
277 |
272 public: |
278 public: |
273 LDBfc (const BfcStatement type, Model* model = nullptr); |
|
274 |
|
275 BfcStatement statement() const; |
279 BfcStatement statement() const; |
276 void setStatement (BfcStatement value); |
280 void setStatement (BfcStatement value); |
277 QString statementToString() const; |
281 QString statementToString() const; |
278 |
282 |
279 static QString statementToString (BfcStatement statement); |
283 static QString statementToString (BfcStatement statement); |
280 |
284 |
|
285 protected: |
|
286 LDBfc (const BfcStatement type, Model* model = nullptr); |
|
287 |
281 private: |
288 private: |
282 BfcStatement m_statement; |
289 BfcStatement m_statement; |
283 }; |
290 }; |
284 |
291 |
285 // |
292 // |
296 LDOBJ_DEFAULTCOLOR (MainColor) |
303 LDOBJ_DEFAULTCOLOR (MainColor) |
297 LDOBJ_SCEMANTIC |
304 LDOBJ_SCEMANTIC |
298 LDOBJ_HAS_MATRIX |
305 LDOBJ_HAS_MATRIX |
299 |
306 |
300 public: |
307 public: |
301 LDSubfileReference(LDDocument* reference, const Matrix& transformationMatrix, const Vertex& position, Model* model = nullptr); |
|
302 |
|
303 // Inlines this subfile. |
308 // Inlines this subfile. |
304 LDDocument* fileInfo() const; |
309 LDDocument* fileInfo() const; |
305 virtual void getVertices (QSet<Vertex>& verts) const override; |
310 virtual void getVertices (QSet<Vertex>& verts) const override; |
306 void inlineContents(Model& model, bool deep, bool render); |
311 void inlineContents(Model& model, bool deep, bool render); |
307 QList<LDPolygon> inlinePolygons(); |
312 QList<LDPolygon> inlinePolygons(); |
308 void setFileInfo (LDDocument* fileInfo); |
313 void setFileInfo (LDDocument* fileInfo); |
309 int triangleCount() const override; |
314 int triangleCount() const override; |
310 |
315 |
|
316 protected: |
|
317 LDSubfileReference(LDDocument* reference, const Matrix& transformationMatrix, const Vertex& position, Model* model = nullptr); |
|
318 |
311 private: |
319 private: |
312 LDDocument* m_fileInfo; |
320 LDDocument* m_fileInfo; |
313 }; |
321 }; |
314 |
322 |
315 // |
323 // |
345 LDOBJ_DEFAULTCOLOR (EdgeColor) |
353 LDOBJ_DEFAULTCOLOR (EdgeColor) |
346 LDOBJ_SCEMANTIC |
354 LDOBJ_SCEMANTIC |
347 LDOBJ_NO_MATRIX |
355 LDOBJ_NO_MATRIX |
348 |
356 |
349 public: |
357 public: |
|
358 LDLine* becomeEdgeLine(); |
|
359 |
|
360 protected: |
350 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); |
361 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); |
351 LDLine* becomeEdgeLine(); |
|
352 }; |
362 }; |
353 |
363 |
354 // |
364 // |
355 // LDTriangle |
365 // LDTriangle |
356 // |
366 // |
388 LDOBJ_DEFAULTCOLOR (MainColor) |
400 LDOBJ_DEFAULTCOLOR (MainColor) |
389 LDOBJ_SCEMANTIC |
401 LDOBJ_SCEMANTIC |
390 LDOBJ_NO_MATRIX |
402 LDOBJ_NO_MATRIX |
391 |
403 |
392 public: |
404 public: |
|
405 int triangleCount() const override; |
|
406 |
|
407 protected: |
393 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model = nullptr); |
408 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model = nullptr); |
394 |
|
395 int triangleCount() const override; |
|
396 }; |
409 }; |
397 |
410 |
398 // |
411 // |
399 // LDOverlay |
412 // LDOverlay |
400 // |
413 // |
441 LDOBJ_DEFAULTCOLOR (EdgeColor) |
454 LDOBJ_DEFAULTCOLOR (EdgeColor) |
442 LDOBJ_SCEMANTIC |
455 LDOBJ_SCEMANTIC |
443 LDOBJ_NO_MATRIX |
456 LDOBJ_NO_MATRIX |
444 |
457 |
445 public: |
458 public: |
446 LDBezierCurve (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); |
|
447 Vertex pointAt (qreal t) const; |
459 Vertex pointAt (qreal t) const; |
448 void rasterize(Model& model, int segments); |
460 void rasterize(Model& model, int segments); |
449 QVector<LDPolygon> rasterizePolygons (int segments); |
461 QVector<LDPolygon> rasterizePolygons (int segments); |
|
462 |
|
463 protected: |
|
464 LDBezierCurve (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); |
450 }; |
465 }; |
451 |
466 |
452 enum |
467 enum |
453 { |
468 { |
454 LowResolution = 16, |
469 LowResolution = 16, |