src/LDObject.h

changeset 642
751a8df42842
parent 641
425b169a82aa
child 690
9e9c52ca955e
equal deleted inserted replaced
641:425b169a82aa 642:751a8df42842
63 // which is a token of the object's type. The object can be casted into 63 // which is a token of the object's type. The object can be casted into
64 // sub-classes based on this enumerator. 64 // sub-classes based on this enumerator.
65 // ============================================================================= 65 // =============================================================================
66 class LDObject 66 class LDObject
67 { 67 {
68 PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE) 68 PROPERTY (public, bool, isHidden, setHidden, STOCK_WRITE)
69 PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE) 69 PROPERTY (public, bool, isSelected, setSelected, STOCK_WRITE)
70 PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE) 70 PROPERTY (public, LDObject*, parent, setParent, STOCK_WRITE)
71 PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) // TODO: rename~ 71 PROPERTY (public, LDDocument*, document, setDocument, STOCK_WRITE)
72 PROPERTY (private, int, ID, NUM_OPS, STOCK_WRITE) 72 PROPERTY (private, int, id, setID, STOCK_WRITE)
73 PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE) 73 PROPERTY (public, int, color, setColor, CUSTOM_WRITE)
74 PROPERTY (public, bool, GLInit, BOOL_OPS, STOCK_WRITE) 74 PROPERTY (public, bool, isGLInit, setGLInit, STOCK_WRITE)
75 75
76 public: 76 public:
77 // Object type codes. 77 // Object type codes.
78 enum Type 78 enum Type
79 { 79 {
225 LDObjectList m_refs; 225 LDObjectList m_refs;
226 Vertex m_data; 226 Vertex m_data;
227 }; 227 };
228 228
229 // ============================================================================= 229 // =============================================================================
230 // LDMatrixObject
231 // =============================================================================
232 // 230 //
233 // Common code for objects with matrices. This class is multiple-derived in 231 // Common code for objects with matrices. This class is multiple-derived in
234 // and thus not used directly other than as a common storage point for matrices 232 // and thus not used directly other than as a common storage point for matrices
235 // and vertices. 233 // and vertices.
236 // 234 //
238 // multiple-derived in, static_cast or dynamic_cast won't budge here. 236 // multiple-derived in, static_cast or dynamic_cast won't budge here.
239 // 237 //
240 // In 0.1-alpha, there was a separate 'radial' type which had a position and 238 // In 0.1-alpha, there was a separate 'radial' type which had a position and
241 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping 239 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping
242 // this class distinct in case I get new extension ideas. :) 240 // this class distinct in case I get new extension ideas. :)
243 // ============================================================================= 241 //
244 class LDMatrixObject 242 class LDMatrixObject
245 { 243 {
246 PROPERTY (public, LDObject*, LinkPointer, NO_OPS, STOCK_WRITE) 244 PROPERTY (public, LDObject*, linkPointer, setLinkPointer, STOCK_WRITE)
247 PROPERTY (public, Matrix, Transform, NO_OPS, CUSTOM_WRITE) 245 PROPERTY (public, Matrix, transform, setTransform, CUSTOM_WRITE)
248 246
249 public: 247 public:
250 LDMatrixObject() : 248 LDMatrixObject() :
251 m_Position (LDSharedVertex::getSharedVertex (g_origin)) {} 249 m_position (LDSharedVertex::getSharedVertex (g_origin)) {}
252 250
253 LDMatrixObject (const Matrix& transform, const Vertex& pos) : 251 LDMatrixObject (const Matrix& transform, const Vertex& pos) :
254 m_Transform (transform), 252 m_transform (transform),
255 m_Position (LDSharedVertex::getSharedVertex (pos)) {} 253 m_position (LDSharedVertex::getSharedVertex (pos)) {}
256 254
257 inline const Vertex& getPosition() const 255 inline const Vertex& position() const
258 { 256 {
259 return m_Position->data(); 257 return m_position->data();
260 } 258 }
261 259
262 void setCoordinate (const Axis ax, double value) 260 void setCoordinate (const Axis ax, double value)
263 { 261 {
264 Vertex v = getPosition(); 262 Vertex v = position();
265 v[ax] = value; 263 v[ax] = value;
266 setPosition (v); 264 setPosition (v);
267 } 265 }
268 266
269 void setPosition (const Vertex& a); 267 void setPosition (const Vertex& a);
270 268
271 private: 269 private:
272 LDSharedVertex* m_Position; 270 LDSharedVertex* m_position;
273 }; 271 };
274 272
275 // ============================================================================= 273 // =============================================================================
276 // LDError
277 // 274 //
278 // Represents a line in the LDraw file that could not be properly parsed. It is 275 // Represents a line in the LDraw file that could not be properly parsed. It is
279 // represented by a (!) ERROR in the code view. It exists for the purpose of 276 // represented by a (!) ERROR in the code view. It exists for the purpose of
280 // allowing garbage lines be debugged and corrected within LDForge. The member 277 // allowing garbage lines be debugged and corrected within LDForge.
281 // zContent contains the contents of the unparsable line. 278 //
282 // =============================================================================
283 class LDError : public LDObject 279 class LDError : public LDObject
284 { 280 {
285 LDOBJ (Error) 281 LDOBJ (Error)
286 LDOBJ_NAME (error) 282 LDOBJ_NAME (error)
287 LDOBJ_VERTICES (0) 283 LDOBJ_VERTICES (0)
288 LDOBJ_UNCOLORED 284 LDOBJ_UNCOLORED
289 LDOBJ_SCEMANTIC 285 LDOBJ_SCEMANTIC
290 LDOBJ_NO_MATRIX 286 LDOBJ_NO_MATRIX
291 PROPERTY (public, QString, FileReferenced, STR_OPS, STOCK_WRITE) 287 PROPERTY (public, QString, fileReferenced, setFileReferenced, STOCK_WRITE)
288 PROPERTY (private, QString, contents, setContents, STOCK_WRITE)
289 PROPERTY (private, QString, reason, setReason, STOCK_WRITE)
292 290
293 public: 291 public:
294 LDError(); 292 LDError();
295 LDError (QString contents, QString reason) : contents (contents), reason (reason) {} 293 LDError (QString contents, QString reason) :
296 294 m_contents (contents),
297 // Content of this unknown line 295 m_reason (reason) {}
298 QString contents; 296 };
299 297
300 // Why is this gibberish? 298 // =============================================================================
301 QString reason;
302 };
303
304 // =============================================================================
305 // LDEmpty
306 // 299 //
307 // Represents an empty line in the LDraw code file. 300 // Represents an empty line in the LDraw code file.
308 // ============================================================================= 301 //
309 class LDEmpty : public LDObject 302 class LDEmpty : public LDObject
310 { 303 {
311 LDOBJ (Empty) 304 LDOBJ (Empty)
312 LDOBJ_NAME (empty) 305 LDOBJ_NAME (empty)
313 LDOBJ_VERTICES (0) 306 LDOBJ_VERTICES (0)
315 LDOBJ_NON_SCEMANTIC 308 LDOBJ_NON_SCEMANTIC
316 LDOBJ_NO_MATRIX 309 LDOBJ_NO_MATRIX
317 }; 310 };
318 311
319 // ============================================================================= 312 // =============================================================================
320 // LDComment 313 //
321 // 314 // Represents a code-0 comment in the LDraw code file.
322 // Represents a code-0 comment in the LDraw code file. Member text contains 315 //
323 // the text of the comment.
324 // =============================================================================
325 class LDComment : public LDObject 316 class LDComment : public LDObject
326 { 317 {
318 PROPERTY (public, QString, text, setText, STOCK_WRITE)
327 LDOBJ (Comment) 319 LDOBJ (Comment)
328 LDOBJ_NAME (comment) 320 LDOBJ_NAME (comment)
329 LDOBJ_VERTICES (0) 321 LDOBJ_VERTICES (0)
330 LDOBJ_UNCOLORED 322 LDOBJ_UNCOLORED
331 LDOBJ_NON_SCEMANTIC 323 LDOBJ_NON_SCEMANTIC
332 LDOBJ_NO_MATRIX 324 LDOBJ_NO_MATRIX
333 325
334 public: 326 public:
335 LDComment() {} 327 LDComment() {}
336 LDComment (QString text) : text (text) {} 328 LDComment (QString text) : m_text (text) {}
337 329 };
338 QString text; // The text of this comment 330
339 }; 331 // =============================================================================
340
341 // =============================================================================
342 // LDBFC
343 // 332 //
344 // Represents a 0 BFC statement in the LDraw code. eStatement contains the type 333 // Represents a 0 BFC statement in the LDraw code. eStatement contains the type
345 // of this statement. 334 // of this statement.
346 // ============================================================================= 335 //
347 class LDBFC : public LDObject 336 class LDBFC : public LDObject
348 { 337 {
349 public: 338 public:
350 enum Statement 339 enum Statement
351 { 340 {
364 353
365 LDOBJ (BFC) 354 LDOBJ (BFC)
366 LDOBJ_NAME (bfc) 355 LDOBJ_NAME (bfc)
367 LDOBJ_VERTICES (0) 356 LDOBJ_VERTICES (0)
368 LDOBJ_UNCOLORED 357 LDOBJ_UNCOLORED
369 LDOBJ_CUSTOM_SCEMANTIC { return (m_statement == InvertNext); } 358 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == InvertNext); }
370 LDOBJ_NO_MATRIX 359 LDOBJ_NO_MATRIX
360 PROPERTY (public, Statement, statement, setStatement, STOCK_WRITE)
371 361
372 public: 362 public:
373 LDBFC() {} 363 LDBFC() {}
374 LDBFC (const LDBFC::Statement type) : 364 LDBFC (const LDBFC::Statement type) :
375 m_statement (type) {} 365 m_statement (type) {}
376 366
377 // Statement strings 367 // Statement strings
378 static const char* k_statementStrings[]; 368 static const char* k_statementStrings[];
379
380 Statement m_statement;
381 }; 369 };
382 370
383 // ============================================================================= 371 // =============================================================================
384 // LDSubfile 372 // LDSubfile
385 // 373 //
391 LDOBJ_NAME (subfile) 379 LDOBJ_NAME (subfile)
392 LDOBJ_VERTICES (0) 380 LDOBJ_VERTICES (0)
393 LDOBJ_COLORED 381 LDOBJ_COLORED
394 LDOBJ_SCEMANTIC 382 LDOBJ_SCEMANTIC
395 LDOBJ_HAS_MATRIX 383 LDOBJ_HAS_MATRIX
396 PROPERTY (public, LDDocumentPointer, FileInfo, NO_OPS, STOCK_WRITE) 384 PROPERTY (public, LDDocumentPointer, fileInfo, setFileInfo, STOCK_WRITE)
397 385
398 public: 386 public:
399 enum InlineFlag 387 enum InlineFlag
400 { 388 {
401 DeepInline = (1 << 0), 389 DeepInline = (1 << 0),
402 CacheInline = (1 << 1), 390 CacheInline = (1 << 1),
403 RendererInline = (1 << 2), 391 RendererInline = (1 << 2),
404 392 DeepCacheInline = (DeepInline | CacheInline),
405 DeepCacheInline = DeepInline | CacheInline,
406 }; 393 };
407 394
408 Q_DECLARE_FLAGS (InlineFlags, InlineFlag) 395 Q_DECLARE_FLAGS (InlineFlags, InlineFlag)
409 396
410 LDSubfile() 397 LDSubfile()
547 LDOBJ_NAME (overlay) 534 LDOBJ_NAME (overlay)
548 LDOBJ_VERTICES (0) 535 LDOBJ_VERTICES (0)
549 LDOBJ_UNCOLORED 536 LDOBJ_UNCOLORED
550 LDOBJ_NON_SCEMANTIC 537 LDOBJ_NON_SCEMANTIC
551 LDOBJ_NO_MATRIX 538 LDOBJ_NO_MATRIX
552 PROPERTY (public, int, Camera, NUM_OPS, STOCK_WRITE) 539 PROPERTY (public, int, camera, setCamera, STOCK_WRITE)
553 PROPERTY (public, int, X, NUM_OPS, STOCK_WRITE) 540 PROPERTY (public, int, x, setX, STOCK_WRITE)
554 PROPERTY (public, int, Y, NUM_OPS, STOCK_WRITE) 541 PROPERTY (public, int, y, setY, STOCK_WRITE)
555 PROPERTY (public, int, Width, NUM_OPS, STOCK_WRITE) 542 PROPERTY (public, int, width, setWidth, STOCK_WRITE)
556 PROPERTY (public, int, Height, NUM_OPS, STOCK_WRITE) 543 PROPERTY (public, int, height, setHeight, STOCK_WRITE)
557 PROPERTY (public, QString, FileName, STR_OPS, STOCK_WRITE) 544 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE)
558 }; 545 };
559 546
560 // Other common LDraw stuff 547 // Other common LDraw stuff
561 static const QString CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt", 548 static const QString g_CALicense ("!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt");
562 NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt"; 549 static const QString g_nonCALicense ("!LICENSE Not redistributable : see NonCAreadme.txt");
563 static const int lores = 16; 550 static const int g_lores = 16;
564 static const int hires = 48; 551 static const int g_hires = 48;
565 552
566 QString getLicenseText (int id); 553 QString getLicenseText (int id);

mercurial