91 // |
90 // |
92 class LDObject |
91 class LDObject |
93 { |
92 { |
94 PROPERTY (public, bool, isHidden, setHidden, STOCK_WRITE) |
93 PROPERTY (public, bool, isHidden, setHidden, STOCK_WRITE) |
95 PROPERTY (public, bool, isSelected, setSelected, STOCK_WRITE) |
94 PROPERTY (public, bool, isSelected, setSelected, STOCK_WRITE) |
96 PROPERTY (public, bool, isDestructed, setDestructed, STOCK_WRITE) |
|
97 PROPERTY (public, LDObject*, parent, setParent, STOCK_WRITE) |
95 PROPERTY (public, LDObject*, parent, setParent, STOCK_WRITE) |
98 PROPERTY (public, LDDocument*, document, setDocument, CUSTOM_WRITE) |
96 PROPERTY (public, LDDocument*, document, setDocument, CUSTOM_WRITE) |
99 PROPERTY (private, int32, id, setID, STOCK_WRITE) |
97 PROPERTY (private, int32, id, setID, STOCK_WRITE) |
100 PROPERTY (public, LDColor, color, setColor, CUSTOM_WRITE) |
98 PROPERTY (public, LDColor, color, setColor, CUSTOM_WRITE) |
101 PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE) |
99 PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE) |
102 PROPERTY (private, LDObjectWeakPtr, self, setSelf, STOCK_WRITE) |
100 PROPERTY (private, LDObjectWeakPtr, self, setSelf, STOCK_WRITE) |
103 |
101 |
104 public: |
102 public: |
105 LDObject (LDDocument* document = nullptr); |
103 LDObject (LDDocument* document = nullptr); |
|
104 virtual ~LDObject(); |
106 |
105 |
107 // This object as LDraw code |
106 // This object as LDraw code |
108 virtual QString asText() const = 0; |
107 virtual QString asText() const = 0; |
109 |
108 |
110 // Makes a copy of this object |
109 // Makes a copy of this object |
111 LDObjectPtr createCopy() const; |
110 LDObject* createCopy() const; |
112 |
111 |
113 // What color does the object default to? |
112 // What color does the object default to? |
114 virtual LDColor defaultColor() const = 0; |
113 virtual LDColor defaultColor() const = 0; |
115 |
114 |
116 // Deletes this object |
115 // Deletes this object |
138 |
137 |
139 // Moves this object using the given vertex as a movement List |
138 // Moves this object using the given vertex as a movement List |
140 void move (Vertex vect); |
139 void move (Vertex vect); |
141 |
140 |
142 // Object after this in the current file |
141 // Object after this in the current file |
143 LDObjectPtr next() const; |
142 LDObject* next() const; |
144 |
143 |
145 // Number of vertices this object has |
144 // Number of vertices this object has |
146 virtual int numVertices() const = 0; |
145 virtual int numVertices() const = 0; |
147 |
146 |
148 // Object prior to this in the current file |
147 // Object prior to this in the current file |
149 LDObjectPtr previous() const; |
148 LDObject* previous() const; |
150 |
149 |
151 // Is the previous object INVERTNEXT? |
150 // Is the previous object INVERTNEXT? |
152 bool previousIsInvertnext (LDBFCPtr& ptr); |
151 bool previousIsInvertnext (LDBFCPtr& ptr); |
153 |
152 |
154 // Replace this LDObject with another LDObject. Object is deleted in the process. |
153 // Replace this LDObject with another LDObject. Object is deleted in the process. |
155 void replace (LDObjectPtr other); |
154 void replace (LDObject* other); |
156 |
155 |
157 // Selects this object. |
156 // Selects this object. |
158 void select(); |
157 void select(); |
159 |
158 |
160 // Set a vertex to the given value |
159 // Set a vertex to the given value |
162 |
161 |
163 // Set a single coordinate of a vertex |
162 // Set a single coordinate of a vertex |
164 void setVertexCoord (int i, Axis ax, double value); |
163 void setVertexCoord (int i, Axis ax, double value); |
165 |
164 |
166 // Swap this object with another. |
165 // Swap this object with another. |
167 void swap (LDObjectPtr other); |
166 void swap (LDObject* other); |
168 |
167 |
169 // What object in the current file ultimately references this? |
168 // What object in the current file ultimately references this? |
170 LDObjectPtr topLevelParent(); |
169 LDObject* topLevelParent(); |
171 |
170 |
172 // Type enumerator of this object |
171 // Type enumerator of this object |
173 virtual LDObjectType type() const = 0; |
172 virtual LDObjectType type() const = 0; |
174 |
173 |
175 // Type name of this object |
174 // Type name of this object |
180 |
179 |
181 // Get type name by enumerator |
180 // Get type name by enumerator |
182 static QString typeName (LDObjectType type); |
181 static QString typeName (LDObjectType type); |
183 |
182 |
184 // Returns a default-constructed LDObject by the given type |
183 // Returns a default-constructed LDObject by the given type |
185 static LDObjectPtr getDefault (const LDObjectType type); |
184 static LDObject* getDefault (const LDObjectType type); |
186 |
185 |
187 // TODO: move this to LDDocument? |
186 // TODO: move this to LDDocument? |
188 static void moveObjects (LDObjectList objs, const bool up); |
187 static void moveObjects (LDObjectList objs, const bool up); |
189 |
188 |
190 // Get a description of a list of LDObjects |
189 // Get a description of a list of LDObjects |
191 static QString describeObjects (const LDObjectList& objs); |
190 static QString describeObjects (const LDObjectList& objs); |
192 static LDObjectPtr fromID (int id); |
191 static LDObject* fromID (int id); |
193 LDPolygon* getPolygon(); |
192 LDPolygon* getPolygon(); |
194 |
193 |
195 // TODO: make this private! |
194 // TODO: make this private! |
196 QListWidgetItem* qObjListEntry; |
195 QListWidgetItem* qObjListEntry; |
197 |
|
198 // This is public because I cannot protect it as the lambda deletor would |
|
199 // have to be the friend. Do not call this! Ever! |
|
200 void finalDelete(); |
|
201 |
|
202 // Even though we supply a custom deleter to QSharedPointer, the shared |
|
203 // pointer's base class still calls operator delete directly in one of |
|
204 // its methods. The method should never be called but we need to declare |
|
205 // the class making this delete call a friend anyway. |
|
206 // |
|
207 // Do not directly delete LDObjects. Ever. |
|
208 virtual ~LDObject(); |
|
209 |
196 |
210 private: |
197 private: |
211 Vertex m_coords[4]; |
198 Vertex m_coords[4]; |
212 |
199 |
213 void chooseID(); |
200 void chooseID(); |
481 public: |
448 public: |
482 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
449 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
483 LDLinePtr toEdgeLine(); |
450 LDLinePtr toEdgeLine(); |
484 }; |
451 }; |
485 |
452 |
486 using LDCondLinePtr = QSharedPointer<LDCondLine>; |
|
487 using LDCondLineWeakPtr = QWeakPointer<LDCondLine>; |
|
488 |
|
489 // |
453 // |
490 // LDTriangle |
454 // LDTriangle |
491 // |
455 // |
492 // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 |
456 // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 |
493 // and v2 contain the end-points of this triangle. dColor is the color the |
457 // and v2 contain the end-points of this triangle. dColor is the color the |
505 |
469 |
506 public: |
470 public: |
507 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr); |
471 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr); |
508 }; |
472 }; |
509 |
473 |
510 using LDTrianglePtr = QSharedPointer<LDTriangle>; |
|
511 using LDTriangleWeakPtr = QWeakPointer<LDTriangle>; |
|
512 |
|
513 // |
474 // |
514 // LDQuad |
475 // LDQuad |
515 // |
476 // |
516 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
477 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
517 // of the quad, dColor is the color used for the quad. |
478 // of the quad, dColor is the color used for the quad. |
582 PROPERTY (public, int, width, setWidth, STOCK_WRITE) |
537 PROPERTY (public, int, width, setWidth, STOCK_WRITE) |
583 PROPERTY (public, int, height, setHeight, STOCK_WRITE) |
538 PROPERTY (public, int, height, setHeight, STOCK_WRITE) |
584 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE) |
539 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE) |
585 }; |
540 }; |
586 |
541 |
587 using LDOverlayPtr = QSharedPointer<LDOverlay>; |
|
588 using LDOverlayWeakPtr = QWeakPointer<LDOverlay>; |
|
589 |
|
590 // Other common LDraw stuff |
542 // Other common LDraw stuff |
591 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " |
543 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " |
592 "see CAreadme.txt"); |
544 "see CAreadme.txt"); |
593 |
545 |
594 enum |
546 enum |
598 }; |
550 }; |
599 |
551 |
600 QString PreferredLicenseText(); |
552 QString PreferredLicenseText(); |
601 |
553 |
602 template<typename T> |
554 template<typename T> |
603 inline void DynamicExecute (LDObjectPtr obj, std::function<void (QSharedPointer<T> const&)> func) |
555 inline void DynamicExecute (LDObject* obj, std::function<void (QSharedPointer<T> const&)> func) |
604 { |
556 { |
605 static_assert (std::is_base_of<LDObject, T>::value, |
557 static_assert (std::is_base_of<LDObject, T>::value, |
606 "DynamicExecute may only be used with LDObject-derivatives"); |
558 "DynamicExecute may only be used with LDObject-derivatives"); |
607 |
559 |
608 if (obj->type() == T::SubclassType) |
560 if (obj->type() == T::SubclassType) |
609 func (obj.staticCast<T>()); |
561 func (static_cast<T*> (obj)); |
610 } |
562 } |
611 |
563 |
612 struct LDIterationBreakage {}; |
564 struct LDIterationBreakage {}; |
613 |
565 |
614 template<typename T> |
566 template<typename T> |