src/ldObject.h

changeset 861
83426c5fa732
parent 860
a496e72af069
child 880
5dcd2e741d1c
equal deleted inserted replaced
860:a496e72af069 861:83426c5fa732
38 38
39 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; } 39 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; }
40 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; } 40 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; }
41 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } 41 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; }
42 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) 42 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true)
43 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) LDOBJ_DEFAULTCOLOR (maincolor()) 43 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) LDOBJ_DEFAULTCOLOR (MainColor())
44 #define LDOBJ_DEFAULTCOLOR(V) public: virtual LDColor defaultColor() const override { return (V); } 44 #define LDOBJ_DEFAULTCOLOR(V) public: virtual LDColor defaultColor() const override { return (V); }
45 45
46 #define LDOBJ_CUSTOM_SCEMANTIC public: virtual bool isScemantic() const override 46 #define LDOBJ_CUSTOM_SCEMANTIC public: virtual bool isScemantic() const override
47 #define LDOBJ_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return true; } 47 #define LDOBJ_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return true; }
48 #define LDOBJ_NON_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return false; } 48 #define LDOBJ_NON_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return false; }
216 // 216 //
217 // Makes a new LDObject. This makes the shared pointer always use the custom 217 // Makes a new LDObject. This makes the shared pointer always use the custom
218 // deleter so that all deletions go through finalDelete(); 218 // deleter so that all deletions go through finalDelete();
219 // 219 //
220 template<typename T, typename... Args> 220 template<typename T, typename... Args>
221 inline QSharedPointer<T> spawn (Args... args) 221 inline QSharedPointer<T> LDSpawn (Args... args)
222 { 222 {
223 static_assert (std::is_base_of<LDObject, T>::value, "spawn may only be used with LDObject-derivatives"); 223 static_assert (std::is_base_of<LDObject, T>::value,
224 "spawn may only be used with LDObject-derivatives");
224 LDObjectPtr ptr; 225 LDObjectPtr ptr;
225 new T (&ptr, args...); 226 new T (&ptr, args...);
226 227
227 // Set default color. This cannot be done in the c-tor. 228 // Set default color. Relying on virtual functions, this cannot be done in the c-tor.
228 if (ptr->isColored()) 229 if (ptr->isColored())
229 ptr->setColor (ptr->defaultColor()); 230 ptr->setColor (ptr->defaultColor());
230 231
231 return ptr.staticCast<T>(); 232 return ptr.staticCast<T>();
232 } 233 }
257 Vertex m_position; 258 Vertex m_position;
258 259
259 public: 260 public:
260 LDMatrixObject (LDObjectPtr* selfptr) : 261 LDMatrixObject (LDObjectPtr* selfptr) :
261 LDObject (selfptr), 262 LDObject (selfptr),
262 m_position (g_origin) {} 263 m_position (Origin) {}
263 264
264 LDMatrixObject (LDObjectPtr* selfptr, const Matrix& transform, const Vertex& pos) : 265 LDMatrixObject (LDObjectPtr* selfptr, const Matrix& transform, const Vertex& pos) :
265 LDObject (selfptr), 266 LDObject (selfptr),
266 m_transform (transform), 267 m_transform (transform),
267 m_position (pos) {} 268 m_position (pos) {}
412 { 413 {
413 LDOBJ (Subfile) 414 LDOBJ (Subfile)
414 LDOBJ_NAME (subfile) 415 LDOBJ_NAME (subfile)
415 LDOBJ_VERTICES (0) 416 LDOBJ_VERTICES (0)
416 LDOBJ_COLORED 417 LDOBJ_COLORED
417 LDOBJ_DEFAULTCOLOR (maincolor()) 418 LDOBJ_DEFAULTCOLOR (MainColor())
418 LDOBJ_SCEMANTIC 419 LDOBJ_SCEMANTIC
419 LDOBJ_HAS_MATRIX 420 LDOBJ_HAS_MATRIX
420 PROPERTY (public, LDDocumentPtr, fileInfo, setFileInfo, CUSTOM_WRITE) 421 PROPERTY (public, LDDocumentPtr, fileInfo, setFileInfo, CUSTOM_WRITE)
421 422
422 public: 423 public:
449 { 450 {
450 LDOBJ (Line) 451 LDOBJ (Line)
451 LDOBJ_NAME (line) 452 LDOBJ_NAME (line)
452 LDOBJ_VERTICES (2) 453 LDOBJ_VERTICES (2)
453 LDOBJ_COLORED 454 LDOBJ_COLORED
454 LDOBJ_DEFAULTCOLOR (edgecolor()) 455 LDOBJ_DEFAULTCOLOR (EdgeColor())
455 LDOBJ_SCEMANTIC 456 LDOBJ_SCEMANTIC
456 LDOBJ_NO_MATRIX 457 LDOBJ_NO_MATRIX
457 458
458 public: 459 public:
459 LDLine (LDObjectPtr* selfptr, Vertex v1, Vertex v2); 460 LDLine (LDObjectPtr* selfptr, Vertex v1, Vertex v2);
471 { 472 {
472 LDOBJ (CondLine) 473 LDOBJ (CondLine)
473 LDOBJ_NAME (condline) 474 LDOBJ_NAME (condline)
474 LDOBJ_VERTICES (4) 475 LDOBJ_VERTICES (4)
475 LDOBJ_COLORED 476 LDOBJ_COLORED
476 LDOBJ_DEFAULTCOLOR (edgecolor()) 477 LDOBJ_DEFAULTCOLOR (EdgeColor())
477 LDOBJ_SCEMANTIC 478 LDOBJ_SCEMANTIC
478 LDOBJ_NO_MATRIX 479 LDOBJ_NO_MATRIX
479 480
480 public: 481 public:
481 LDCondLine (LDObjectPtr* selfptr, const Vertex& v0, const Vertex& v1, 482 LDCondLine (LDObjectPtr* selfptr, const Vertex& v0, const Vertex& v1,
497 { 498 {
498 LDOBJ (Triangle) 499 LDOBJ (Triangle)
499 LDOBJ_NAME (triangle) 500 LDOBJ_NAME (triangle)
500 LDOBJ_VERTICES (3) 501 LDOBJ_VERTICES (3)
501 LDOBJ_COLORED 502 LDOBJ_COLORED
502 LDOBJ_DEFAULTCOLOR (maincolor()) 503 LDOBJ_DEFAULTCOLOR (MainColor())
503 LDOBJ_SCEMANTIC 504 LDOBJ_SCEMANTIC
504 LDOBJ_NO_MATRIX 505 LDOBJ_NO_MATRIX
505 506
506 public: 507 public:
507 LDTriangle (LDObjectPtr* selfptr, Vertex const& v1, 508 LDTriangle (LDObjectPtr* selfptr, Vertex const& v1,
521 { 522 {
522 LDOBJ (Quad) 523 LDOBJ (Quad)
523 LDOBJ_NAME (quad) 524 LDOBJ_NAME (quad)
524 LDOBJ_VERTICES (4) 525 LDOBJ_VERTICES (4)
525 LDOBJ_COLORED 526 LDOBJ_COLORED
526 LDOBJ_DEFAULTCOLOR (maincolor()) 527 LDOBJ_DEFAULTCOLOR (MainColor())
527 LDOBJ_SCEMANTIC 528 LDOBJ_SCEMANTIC
528 LDOBJ_NO_MATRIX 529 LDOBJ_NO_MATRIX
529 530
530 public: 531 public:
531 LDQuad (LDObjectPtr* selfptr, const Vertex& v1, const Vertex& v2, 532 LDQuad (LDObjectPtr* selfptr, const Vertex& v1, const Vertex& v2,
550 { 551 {
551 LDOBJ (Vertex) 552 LDOBJ (Vertex)
552 LDOBJ_NAME (vertex) 553 LDOBJ_NAME (vertex)
553 LDOBJ_VERTICES (0) // TODO: move pos to m_vertices[0] 554 LDOBJ_VERTICES (0) // TODO: move pos to m_vertices[0]
554 LDOBJ_COLORED 555 LDOBJ_COLORED
555 LDOBJ_DEFAULTCOLOR (maincolor()) 556 LDOBJ_DEFAULTCOLOR (MainColor())
556 LDOBJ_NON_SCEMANTIC 557 LDOBJ_NON_SCEMANTIC
557 LDOBJ_NO_MATRIX 558 LDOBJ_NO_MATRIX
558 559
559 public: 560 public:
560 Vertex pos; 561 Vertex pos;
581 PROPERTY (public, int, camera, setCamera, STOCK_WRITE) 582 PROPERTY (public, int, camera, setCamera, STOCK_WRITE)
582 PROPERTY (public, int, x, setX, STOCK_WRITE) 583 PROPERTY (public, int, x, setX, STOCK_WRITE)
583 PROPERTY (public, int, y, setY, STOCK_WRITE) 584 PROPERTY (public, int, y, setY, STOCK_WRITE)
584 PROPERTY (public, int, width, setWidth, STOCK_WRITE) 585 PROPERTY (public, int, width, setWidth, STOCK_WRITE)
585 PROPERTY (public, int, height, setHeight, STOCK_WRITE) 586 PROPERTY (public, int, height, setHeight, STOCK_WRITE)
586 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE) 587 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE)
587 }; 588 };
588 589
589 using LDOverlayPtr = QSharedPointer<LDOverlay>; 590 using LDOverlayPtr = QSharedPointer<LDOverlay>;
590 using LDOverlayWeakPtr = QWeakPointer<LDOverlay>; 591 using LDOverlayWeakPtr = QWeakPointer<LDOverlay>;
591 592
592 // Other common LDraw stuff 593 // Other common LDraw stuff
593 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " 594 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : "
594 "see CAreadme.txt"); 595 "see CAreadme.txt");
595 static const int LowResolution = 16; 596
596 static const int HighResolution = 48; 597 enum
598 {
599 LowResolution = 16,
600 HighResolution = 48
601 };
597 602
598 QString PreferredLicenseText(); 603 QString PreferredLicenseText();
599 604
600 template<typename T> 605 template<typename T>
601 inline void DynamicExecute (LDObjectPtr obj, std::function<void (QSharedPointer<T> const&)> func) 606 inline void DynamicExecute (LDObjectPtr obj, std::function<void (QSharedPointer<T> const&)> func)

mercurial