30 { \ |
28 { \ |
31 return new LD##T (*this); \ |
29 return new LD##T (*this); \ |
32 } \ |
30 } \ |
33 \ |
31 \ |
34 public: \ |
32 public: \ |
35 virtual LDObject::Type getType() const override \ |
33 virtual LDObject::Type type() const override \ |
36 { \ |
34 { \ |
37 return LDObject::E##T; \ |
35 return LDObject::E##T; \ |
38 } \ |
36 } \ |
39 virtual QString raw() const override; \ |
37 virtual QString asText() const override; \ |
40 virtual void invert() override; |
38 virtual void invert() override; |
41 |
39 |
42 #define LDOBJ_NAME(N) virtual QString getTypeName() const override { return #N; } |
40 #define LDOBJ_NAME(N) virtual QString typeName() const override { return #N; } |
43 #define LDOBJ_VERTICES(V) virtual int vertices() const override { return V; } |
41 #define LDOBJ_VERTICES(V) virtual int vertices() const override { return V; } |
44 #define LDOBJ_SETCOLORED(V) virtual bool isColored() const override { return V; } |
42 #define LDOBJ_SETCOLORED(V) virtual bool isColored() const override { return V; } |
45 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
43 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
46 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) |
44 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) |
47 |
45 |
66 // which is a token of the object's type. The object can be casted into |
64 // which is a token of the object's type. The object can be casted into |
67 // sub-classes based on this enumerator. |
65 // sub-classes based on this enumerator. |
68 // ============================================================================= |
66 // ============================================================================= |
69 class LDObject |
67 class LDObject |
70 { |
68 { |
71 PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE) |
69 PROPERTY (public, bool, isHidden, setHidden, STOCK_WRITE) |
72 PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE) |
70 PROPERTY (public, bool, isSelected, setSelected, STOCK_WRITE) |
73 PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE) |
71 PROPERTY (public, LDObject*, parent, setParent, STOCK_WRITE) |
74 PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) // TODO: rename~ |
72 PROPERTY (public, LDDocument*, document, setDocument, STOCK_WRITE) |
75 PROPERTY (private, int, ID, NUM_OPS, STOCK_WRITE) |
73 PROPERTY (private, int, id, setID, STOCK_WRITE) |
76 PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE) |
74 PROPERTY (public, int, color, setColor, CUSTOM_WRITE) |
77 PROPERTY (public, bool, GLInit, BOOL_OPS, STOCK_WRITE) |
75 PROPERTY (public, bool, isGLInit, setGLInit, STOCK_WRITE) |
78 PROPERTY (public, QString, Origin, NO_OPS, STOCK_WRITE) |
76 PROPERTY (public, QString, origin, setOrigin, STOCK_WRITE) |
79 |
77 |
80 public: |
78 public: |
81 // Object type codes. |
79 // Object type codes. |
82 enum Type |
80 enum Type |
83 { |
81 { |
100 |
98 |
101 // Makes a copy of this object |
99 // Makes a copy of this object |
102 LDObject* createCopy() const; |
100 LDObject* createCopy() const; |
103 |
101 |
104 // Deletes this object |
102 // Deletes this object |
105 void deleteSelf(); |
103 void destroy(); |
106 |
104 |
107 // Index (i.e. line number) of this object |
105 // Index (i.e. line number) of this object |
108 long getIndex() const; |
106 long lineNumber() const; |
109 |
107 |
110 // Type enumerator of this object |
108 // Type enumerator of this object |
111 virtual Type getType() const = 0; |
109 virtual Type type() const = 0; |
112 |
110 |
113 // Get a vertex by index |
111 // Get a vertex by index |
114 const Vertex& getVertex (int i) const; |
112 const Vertex& vertex (int i) const; |
115 |
113 |
116 // Type name of this object |
114 // Type name of this object |
117 virtual QString getTypeName() const = 0; |
115 virtual QString typeName() const = 0; |
118 |
116 |
119 // Does this object have a matrix and position? (see LDMatrixObject) |
117 // Does this object have a matrix and position? (see LDMatrixObject) |
120 virtual bool hasMatrix() const = 0; |
118 virtual bool hasMatrix() const = 0; |
121 |
119 |
122 // Inverts this object (winding is reversed) |
120 // Inverts this object (winding is reversed) |
133 |
131 |
134 // Object after this in the current file |
132 // Object after this in the current file |
135 LDObject* next() const; |
133 LDObject* next() const; |
136 |
134 |
137 // Object prior to this in the current file |
135 // Object prior to this in the current file |
138 LDObject* prev() const; |
136 LDObject* previous() const; |
139 |
137 |
140 // This object as LDraw code |
138 // This object as LDraw code |
141 virtual QString raw() const = 0; |
139 virtual QString asText() const = 0; |
142 |
140 |
143 // Replace this LDObject with another LDObject. Object is deleted in the process. |
141 // Replace this LDObject with another LDObject. Object is deleted in the process. |
144 void replace (LDObject* other); |
142 void replace (LDObject* other); |
145 |
143 |
146 // Selects this object. |
144 // Selects this object. |
243 // multiple-derived in, static_cast or dynamic_cast won't budge here. |
239 // multiple-derived in, static_cast or dynamic_cast won't budge here. |
244 // |
240 // |
245 // In 0.1-alpha, there was a separate 'radial' type which had a position and |
241 // In 0.1-alpha, there was a separate 'radial' type which had a position and |
246 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping |
242 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping |
247 // this class distinct in case I get new extension ideas. :) |
243 // this class distinct in case I get new extension ideas. :) |
248 // ============================================================================= |
244 // |
249 class LDMatrixObject |
245 class LDMatrixObject |
250 { |
246 { |
251 PROPERTY (public, LDObject*, LinkPointer, NO_OPS, STOCK_WRITE) |
247 PROPERTY (public, LDObject*, linkPointer, setLinkPointer, STOCK_WRITE) |
252 PROPERTY (public, Matrix, Transform, NO_OPS, CUSTOM_WRITE) |
248 PROPERTY (public, Matrix, transform, setTransform, CUSTOM_WRITE) |
253 |
249 |
254 public: |
250 public: |
255 LDMatrixObject() : |
251 LDMatrixObject() : |
256 m_Position (LDSharedVertex::getSharedVertex (g_origin)) {} |
252 m_position (LDSharedVertex::getSharedVertex (g_origin)) {} |
257 |
253 |
258 LDMatrixObject (const Matrix& transform, const Vertex& pos) : |
254 LDMatrixObject (const Matrix& transform, const Vertex& pos) : |
259 m_Transform (transform), |
255 m_transform (transform), |
260 m_Position (LDSharedVertex::getSharedVertex (pos)) {} |
256 m_position (LDSharedVertex::getSharedVertex (pos)) {} |
261 |
257 |
262 inline const Vertex& getPosition() const |
258 inline const Vertex& position() const |
263 { |
259 { |
264 return m_Position->data(); |
260 return m_position->data(); |
265 } |
261 } |
266 |
262 |
267 void setCoordinate (const Axis ax, double value) |
263 void setCoordinate (const Axis ax, double value) |
268 { |
264 { |
269 Vertex v = getPosition(); |
265 Vertex v = position(); |
270 v[ax] = value; |
266 v[ax] = value; |
271 setPosition (v); |
267 setPosition (v); |
272 } |
268 } |
273 |
269 |
274 void setPosition (const Vertex& a); |
270 void setPosition (const Vertex& a); |
275 |
271 |
276 private: |
272 private: |
277 LDSharedVertex* m_Position; |
273 LDSharedVertex* m_position; |
278 }; |
274 }; |
279 |
275 |
280 // ============================================================================= |
276 // ============================================================================= |
281 // LDError |
|
282 // |
277 // |
283 // Represents a line in the LDraw file that could not be properly parsed. It is |
278 // Represents a line in the LDraw file that could not be properly parsed. It is |
284 // represented by a (!) ERROR in the code view. It exists for the purpose of |
279 // represented by a (!) ERROR in the code view. It exists for the purpose of |
285 // allowing garbage lines be debugged and corrected within LDForge. The member |
280 // allowing garbage lines be debugged and corrected within LDForge. |
286 // zContent contains the contents of the unparsable line. |
281 // |
287 // ============================================================================= |
|
288 class LDError : public LDObject |
282 class LDError : public LDObject |
289 { |
283 { |
290 LDOBJ (Error) |
284 LDOBJ (Error) |
291 LDOBJ_NAME (error) |
285 LDOBJ_NAME (error) |
292 LDOBJ_VERTICES (0) |
286 LDOBJ_VERTICES (0) |
293 LDOBJ_UNCOLORED |
287 LDOBJ_UNCOLORED |
294 LDOBJ_SCEMANTIC |
288 LDOBJ_SCEMANTIC |
295 LDOBJ_NO_MATRIX |
289 LDOBJ_NO_MATRIX |
296 PROPERTY (public, QString, FileReferenced, STR_OPS, STOCK_WRITE) |
290 PROPERTY (public, QString, fileReferenced, setFileReferenced, STOCK_WRITE) |
|
291 PROPERTY (private, QString, contents, setContents, STOCK_WRITE) |
|
292 PROPERTY (private, QString, reason, setReason, STOCK_WRITE) |
297 |
293 |
298 public: |
294 public: |
299 LDError(); |
295 LDError(); |
300 LDError (QString contents, QString reason) : contents (contents), reason (reason) {} |
296 LDError (QString contents, QString reason) : |
301 |
297 m_contents (contents), |
302 // Content of this unknown line |
298 m_reason (reason) {} |
303 QString contents; |
299 }; |
304 |
300 |
305 // Why is this gibberish? |
301 // ============================================================================= |
306 QString reason; |
|
307 }; |
|
308 |
|
309 // ============================================================================= |
|
310 // LDEmpty |
|
311 // |
302 // |
312 // Represents an empty line in the LDraw code file. |
303 // Represents an empty line in the LDraw code file. |
313 // ============================================================================= |
304 // |
314 class LDEmpty : public LDObject |
305 class LDEmpty : public LDObject |
315 { |
306 { |
316 LDOBJ (Empty) |
307 LDOBJ (Empty) |
317 LDOBJ_NAME (empty) |
308 LDOBJ_NAME (empty) |
318 LDOBJ_VERTICES (0) |
309 LDOBJ_VERTICES (0) |
320 LDOBJ_NON_SCEMANTIC |
311 LDOBJ_NON_SCEMANTIC |
321 LDOBJ_NO_MATRIX |
312 LDOBJ_NO_MATRIX |
322 }; |
313 }; |
323 |
314 |
324 // ============================================================================= |
315 // ============================================================================= |
325 // LDComment |
316 // |
326 // |
317 // Represents a code-0 comment in the LDraw code file. |
327 // Represents a code-0 comment in the LDraw code file. Member text contains |
318 // |
328 // the text of the comment. |
|
329 // ============================================================================= |
|
330 class LDComment : public LDObject |
319 class LDComment : public LDObject |
331 { |
320 { |
|
321 PROPERTY (public, QString, text, setText, STOCK_WRITE) |
332 LDOBJ (Comment) |
322 LDOBJ (Comment) |
333 LDOBJ_NAME (comment) |
323 LDOBJ_NAME (comment) |
334 LDOBJ_VERTICES (0) |
324 LDOBJ_VERTICES (0) |
335 LDOBJ_UNCOLORED |
325 LDOBJ_UNCOLORED |
336 LDOBJ_NON_SCEMANTIC |
326 LDOBJ_NON_SCEMANTIC |
337 LDOBJ_NO_MATRIX |
327 LDOBJ_NO_MATRIX |
338 |
328 |
339 public: |
329 public: |
340 LDComment() {} |
330 LDComment() {} |
341 LDComment (QString text) : text (text) {} |
331 LDComment (QString text) : m_text (text) {} |
342 |
332 }; |
343 QString text; // The text of this comment |
333 |
344 }; |
334 // ============================================================================= |
345 |
|
346 // ============================================================================= |
|
347 // LDBFC |
|
348 // |
335 // |
349 // Represents a 0 BFC statement in the LDraw code. eStatement contains the type |
336 // Represents a 0 BFC statement in the LDraw code. eStatement contains the type |
350 // of this statement. |
337 // of this statement. |
351 // ============================================================================= |
338 // |
352 class LDBFC : public LDObject |
339 class LDBFC : public LDObject |
353 { |
340 { |
354 public: |
341 public: |
355 enum Type |
342 enum Statement |
356 { |
343 { |
357 CertifyCCW, |
344 CertifyCCW, |
358 CCW, |
345 CCW, |
359 CertifyCW, |
346 CertifyCW, |
360 CW, |
347 CW, |
396 LDOBJ_NAME (subfile) |
382 LDOBJ_NAME (subfile) |
397 LDOBJ_VERTICES (0) |
383 LDOBJ_VERTICES (0) |
398 LDOBJ_COLORED |
384 LDOBJ_COLORED |
399 LDOBJ_SCEMANTIC |
385 LDOBJ_SCEMANTIC |
400 LDOBJ_HAS_MATRIX |
386 LDOBJ_HAS_MATRIX |
401 PROPERTY (public, LDDocumentPointer, FileInfo, NO_OPS, CUSTOM_WRITE) |
387 PROPERTY (public, LDDocumentPointer, fileInfo, setFileInfo, CUSTOM_WRITE) |
402 |
388 |
403 public: |
389 public: |
404 enum InlineFlag |
390 enum InlineFlag |
405 { |
391 { |
406 DeepInline = (1 << 0), |
392 DeepInline = (1 << 0), |
407 CacheInline = (1 << 1), |
393 CacheInline = (1 << 1), |
408 RendererInline = (1 << 2), |
394 RendererInline = (1 << 2), |
409 |
395 DeepCacheInline = (DeepInline | CacheInline), |
410 DeepCacheInline = DeepInline | CacheInline, |
|
411 }; |
396 }; |
412 |
397 |
413 Q_DECLARE_FLAGS (InlineFlags, InlineFlag) |
398 Q_DECLARE_FLAGS (InlineFlags, InlineFlag) |
414 |
399 |
415 LDSubfile() |
400 LDSubfile() |
553 LDOBJ_NAME (overlay) |
538 LDOBJ_NAME (overlay) |
554 LDOBJ_VERTICES (0) |
539 LDOBJ_VERTICES (0) |
555 LDOBJ_UNCOLORED |
540 LDOBJ_UNCOLORED |
556 LDOBJ_NON_SCEMANTIC |
541 LDOBJ_NON_SCEMANTIC |
557 LDOBJ_NO_MATRIX |
542 LDOBJ_NO_MATRIX |
558 PROPERTY (public, int, Camera, NUM_OPS, STOCK_WRITE) |
543 PROPERTY (public, int, camera, setCamera, STOCK_WRITE) |
559 PROPERTY (public, int, X, NUM_OPS, STOCK_WRITE) |
544 PROPERTY (public, int, x, setX, STOCK_WRITE) |
560 PROPERTY (public, int, Y, NUM_OPS, STOCK_WRITE) |
545 PROPERTY (public, int, y, setY, STOCK_WRITE) |
561 PROPERTY (public, int, Width, NUM_OPS, STOCK_WRITE) |
546 PROPERTY (public, int, width, setWidth, STOCK_WRITE) |
562 PROPERTY (public, int, Height, NUM_OPS, STOCK_WRITE) |
547 PROPERTY (public, int, height, setHeight, STOCK_WRITE) |
563 PROPERTY (public, QString, FileName, STR_OPS, STOCK_WRITE) |
548 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE) |
564 }; |
549 }; |
565 |
550 |
566 // Other common LDraw stuff |
551 // Other common LDraw stuff |
567 static const QString CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt", |
552 static const QString g_CALicense ("!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt"); |
568 NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt"; |
553 static const QString g_nonCALicense ("!LICENSE Not redistributable : see NonCAreadme.txt"); |
569 static const int lores = 16; |
554 static const int g_lores = 16; |
570 static const int hires = 48; |
555 static const int g_hires = 48; |
571 |
556 |
572 QString getLicenseText (int id); |
557 QString getLicenseText (int id); |
573 |
|
574 #endif // LDFORGE_LDTYPES_H |
|