src/ldObject.h

changeset 946
9cbd658b63f9
parent 945
c310073e4f22
child 956
2af18ba2665f
equal deleted inserted replaced
945:c310073e4f22 946:9cbd658b63f9
24 #include "colors.h" 24 #include "colors.h"
25 25
26 #define LDOBJ(T) \ 26 #define LDOBJ(T) \
27 public: \ 27 public: \
28 static constexpr LDObjectType SubclassType = OBJ_##T; \ 28 static constexpr LDObjectType SubclassType = OBJ_##T; \
29 LD##T (LDObject** selfptr); \ 29 LD##T (LDDocument* document = nullptr); \
30 \ 30 \
31 virtual LDObjectType type() const override \ 31 virtual LDObjectType type() const override \
32 { \ 32 { \
33 return OBJ_##T; \ 33 return OBJ_##T; \
34 } \ 34 } \
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; }
95 PROPERTY (public, LDObject*, parent, setParent, STOCK_WRITE) 95 PROPERTY (public, LDObject*, parent, setParent, STOCK_WRITE)
96 PROPERTY (public, LDDocument*, document, setDocument, CUSTOM_WRITE) 96 PROPERTY (public, LDDocument*, document, setDocument, CUSTOM_WRITE)
97 PROPERTY (private, int32, id, setID, STOCK_WRITE) 97 PROPERTY (private, int32, id, setID, STOCK_WRITE)
98 PROPERTY (public, LDColor, color, setColor, CUSTOM_WRITE) 98 PROPERTY (public, LDColor, color, setColor, CUSTOM_WRITE)
99 PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE) 99 PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE)
100 PROPERTY (private, LDObject*, self, setSelf, STOCK_WRITE)
101 100
102 public: 101 public:
103 LDObject (LDDocument* document = nullptr); 102 LDObject (LDDocument* document = nullptr);
104 virtual ~LDObject(); 103 virtual ~LDObject();
105 104
212 T* result = new T (args..., nullptr); 211 T* result = new T (args..., nullptr);
213 212
214 // Set default color. Relying on virtual functions, this cannot be done in the c-tor. 213 // Set default color. Relying on virtual functions, this cannot be done in the c-tor.
215 // TODO: store -1 as the default color 214 // TODO: store -1 as the default color
216 if (result->isColored()) 215 if (result->isColored())
217 result->setColor (ptr->defaultColor()); 216 result->setColor (result->defaultColor());
218 217
219 return result; 218 return result;
220 }
221
222 //
223 // Apparently QPointer doesn't implement operator<. This is a problem when
224 // some of the code needs to sort and remove duplicates from LDObject lists.
225 // Adding a specialized version here:
226 //
227 inline bool operator< (LDObject* a, LDObject* b)
228 {
229 return a.data() < b.data();
230 } 219 }
231 220
232 // 221 //
233 // 222 //
234 // Common code for objects with matrices. This class is multiple-derived in 223 // Common code for objects with matrices. This class is multiple-derived in
385 { 374 {
386 LDOBJ (Subfile) 375 LDOBJ (Subfile)
387 LDOBJ_NAME (subfile) 376 LDOBJ_NAME (subfile)
388 LDOBJ_VERTICES (0) 377 LDOBJ_VERTICES (0)
389 LDOBJ_COLORED 378 LDOBJ_COLORED
390 LDOBJ_DEFAULTCOLOR (MainColor()) 379 LDOBJ_DEFAULTCOLOR (MainColor)
391 LDOBJ_SCEMANTIC 380 LDOBJ_SCEMANTIC
392 LDOBJ_HAS_MATRIX 381 LDOBJ_HAS_MATRIX
393 PROPERTY (public, LDDocument*, fileInfo, setFileInfo, CUSTOM_WRITE) 382 PROPERTY (public, LDDocument*, fileInfo, setFileInfo, CUSTOM_WRITE)
394 383
395 public: 384 public:
420 { 409 {
421 LDOBJ (Line) 410 LDOBJ (Line)
422 LDOBJ_NAME (line) 411 LDOBJ_NAME (line)
423 LDOBJ_VERTICES (2) 412 LDOBJ_VERTICES (2)
424 LDOBJ_COLORED 413 LDOBJ_COLORED
425 LDOBJ_DEFAULTCOLOR (EdgeColor()) 414 LDOBJ_DEFAULTCOLOR (EdgeColor)
426 LDOBJ_SCEMANTIC 415 LDOBJ_SCEMANTIC
427 LDOBJ_NO_MATRIX 416 LDOBJ_NO_MATRIX
428 417
429 public: 418 public:
430 LDLine (Vertex v1, Vertex v2, LDDocument* document = nullptr); 419 LDLine (Vertex v1, Vertex v2, LDDocument* document = nullptr);
439 { 428 {
440 LDOBJ (CondLine) 429 LDOBJ (CondLine)
441 LDOBJ_NAME (condline) 430 LDOBJ_NAME (condline)
442 LDOBJ_VERTICES (4) 431 LDOBJ_VERTICES (4)
443 LDOBJ_COLORED 432 LDOBJ_COLORED
444 LDOBJ_DEFAULTCOLOR (EdgeColor()) 433 LDOBJ_DEFAULTCOLOR (EdgeColor)
445 LDOBJ_SCEMANTIC 434 LDOBJ_SCEMANTIC
446 LDOBJ_NO_MATRIX 435 LDOBJ_NO_MATRIX
447 436
448 public: 437 public:
449 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); 438 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr);
461 { 450 {
462 LDOBJ (Triangle) 451 LDOBJ (Triangle)
463 LDOBJ_NAME (triangle) 452 LDOBJ_NAME (triangle)
464 LDOBJ_VERTICES (3) 453 LDOBJ_VERTICES (3)
465 LDOBJ_COLORED 454 LDOBJ_COLORED
466 LDOBJ_DEFAULTCOLOR (MainColor()) 455 LDOBJ_DEFAULTCOLOR (MainColor)
467 LDOBJ_SCEMANTIC 456 LDOBJ_SCEMANTIC
468 LDOBJ_NO_MATRIX 457 LDOBJ_NO_MATRIX
469 458
470 public: 459 public:
471 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr); 460 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr);
481 { 470 {
482 LDOBJ (Quad) 471 LDOBJ (Quad)
483 LDOBJ_NAME (quad) 472 LDOBJ_NAME (quad)
484 LDOBJ_VERTICES (4) 473 LDOBJ_VERTICES (4)
485 LDOBJ_COLORED 474 LDOBJ_COLORED
486 LDOBJ_DEFAULTCOLOR (MainColor()) 475 LDOBJ_DEFAULTCOLOR (MainColor)
487 LDOBJ_SCEMANTIC 476 LDOBJ_SCEMANTIC
488 LDOBJ_NO_MATRIX 477 LDOBJ_NO_MATRIX
489 478
490 public: 479 public:
491 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document = nullptr); 480 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document = nullptr);
506 { 495 {
507 LDOBJ (Vertex) 496 LDOBJ (Vertex)
508 LDOBJ_NAME (vertex) 497 LDOBJ_NAME (vertex)
509 LDOBJ_VERTICES (0) // TODO: move pos to m_vertices[0] 498 LDOBJ_VERTICES (0) // TODO: move pos to m_vertices[0]
510 LDOBJ_COLORED 499 LDOBJ_COLORED
511 LDOBJ_DEFAULTCOLOR (MainColor()) 500 LDOBJ_DEFAULTCOLOR (MainColor)
512 LDOBJ_NON_SCEMANTIC 501 LDOBJ_NON_SCEMANTIC
513 LDOBJ_NO_MATRIX 502 LDOBJ_NO_MATRIX
514 503
515 public: 504 public:
516 Vertex pos; 505 Vertex pos;

mercurial