65 OBJ_Subfile, // Object represents a sub-file reference |
65 OBJ_Subfile, // Object represents a sub-file reference |
66 OBJ_Quad, // Object represents a quadrilateral |
66 OBJ_Quad, // Object represents a quadrilateral |
67 OBJ_Triangle, // Object represents a triangle |
67 OBJ_Triangle, // Object represents a triangle |
68 OBJ_Line, // Object represents a line |
68 OBJ_Line, // Object represents a line |
69 OBJ_CondLine, // Object represents a conditional line |
69 OBJ_CondLine, // Object represents a conditional line |
70 OBJ_BFC, // Object represents a BFC statement |
70 OBJ_Bfc, // Object represents a BFC statement |
71 OBJ_Overlay, // Object contains meta-info about an overlay image. |
71 OBJ_Overlay, // Object contains meta-info about an overlay image. |
72 OBJ_Comment, // Object represents a comment |
72 OBJ_Comment, // Object represents a comment |
73 OBJ_Error, // Object is the result of failed parsing |
73 OBJ_Error, // Object is the result of failed parsing |
74 OBJ_Empty, // Object represents an empty line |
74 OBJ_Empty, // Object represents an empty line |
75 |
75 |
87 // which is a token of the object's type. The object can be casted into |
87 // which is a token of the object's type. The object can be casted into |
88 // sub-classes based on this enumerator. |
88 // sub-classes based on this enumerator. |
89 // |
89 // |
90 class LDObject |
90 class LDObject |
91 { |
91 { |
92 PROPERTY (public, bool, isHidden, setHidden, STOCK_WRITE) |
|
93 PROPERTY (public, bool, isSelected, setSelected, STOCK_WRITE) |
|
94 PROPERTY (public, LDObject*, parent, setParent, STOCK_WRITE) |
|
95 PROPERTY (public, LDDocument*, document, setDocument, CUSTOM_WRITE) |
|
96 PROPERTY (private, int32, id, setID, STOCK_WRITE) |
|
97 PROPERTY (public, LDColor, color, setColor, CUSTOM_WRITE) |
|
98 PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE) |
|
99 |
|
100 public: |
92 public: |
101 LDObject (LDDocument* document = nullptr); |
93 LDObject (LDDocument* document = nullptr); |
102 |
94 |
103 // This object as LDraw code |
95 virtual QString asText() const = 0; // This object as LDraw code |
104 virtual QString asText() const = 0; |
96 LDColor color() const; |
105 |
97 LDObject* createCopy() const; |
106 // Makes a copy of this object |
98 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
107 LDObject* createCopy() const; |
99 void deselect(); |
108 |
100 void destroy(); |
109 // What color does the object default to? |
101 LDDocument* document() const; |
110 virtual LDColor defaultColor() const = 0; |
102 LDPolygon* getPolygon(); |
111 |
103 virtual void getVertices (QVector<Vertex>& verts) const; |
112 // Deletes this object |
104 virtual bool hasMatrix() const = 0; // Does this object have a matrix and position? (see LDMatrixObject) |
113 void destroy(); |
105 qint32 id() const; |
114 |
106 virtual void invert() = 0; // Inverts this object (winding is reversed) |
115 // Removes this object from selection |
107 virtual bool isColored() const = 0; |
116 void deselect(); |
108 bool isDestroyed() const; |
117 |
109 bool isHidden() const; |
118 virtual void getVertices (QVector<Vertex>& verts) const; |
110 virtual bool isScemantic() const = 0; // Does this object have meaning in the part model? |
119 |
111 bool isSelected() const; |
120 // Does this object have a matrix and position? (see LDMatrixObject) |
112 int lineNumber() const; |
121 virtual bool hasMatrix() const = 0; |
113 void move (Vertex vect); |
122 |
114 LDObject* next() const; |
123 // Inverts this object (winding is reversed) |
115 virtual int numVertices() const = 0; |
124 virtual void invert() = 0; |
116 LDObject* parent() const; |
125 |
117 LDObject* previous() const; |
126 // Is this object colored? |
118 bool previousIsInvertnext (LDBfc*& ptr); |
127 virtual bool isColored() const = 0; |
119 QColor randomColor() const; |
128 |
120 void replace (LDObject* other); |
129 // Does this object have meaning in the part model? |
121 void select(); |
130 virtual bool isScemantic() const = 0; |
122 void setColor (LDColor color); |
131 |
123 void setDocument (LDDocument* document); |
132 // Index (i.e. line number) of this object |
124 void setHidden (bool value); |
133 long lineNumber() const; |
125 void setParent (LDObject* parent); |
134 |
126 void setVertex (int i, const Vertex& vert); |
135 // Moves this object using the given vertex as a movement List |
127 void swap (LDObject* other); |
136 void move (Vertex vect); |
128 LDObject* topLevelParent(); |
137 |
129 virtual LDObjectType type() const = 0; |
138 // Object after this in the current file |
130 virtual QString typeName() const = 0; |
139 LDObject* next() const; |
131 const Vertex& vertex (int i) const; |
140 |
132 |
141 // Number of vertices this object has |
|
142 virtual int numVertices() const = 0; |
|
143 |
|
144 // Object prior to this in the current file |
|
145 LDObject* previous() const; |
|
146 |
|
147 // Is the previous object INVERTNEXT? |
|
148 bool previousIsInvertnext (LDBFC*& ptr); |
|
149 |
|
150 // Replace this LDObject with another LDObject. Object is deleted in the process. |
|
151 void replace (LDObject* other); |
|
152 |
|
153 // Selects this object. |
|
154 void select(); |
|
155 |
|
156 // Set a vertex to the given value |
|
157 void setVertex (int i, const Vertex& vert); |
|
158 |
|
159 // Set a single coordinate of a vertex |
|
160 void setVertexCoord (int i, Axis ax, double value); |
|
161 |
|
162 // Swap this object with another. |
|
163 void swap (LDObject* other); |
|
164 |
|
165 // What object in the current file ultimately references this? |
|
166 LDObject* topLevelParent(); |
|
167 |
|
168 // Type enumerator of this object |
|
169 virtual LDObjectType type() const = 0; |
|
170 |
|
171 // Type name of this object |
|
172 virtual QString typeName() const = 0; |
|
173 |
|
174 // Get a vertex by index |
|
175 const Vertex& vertex (int i) const; |
|
176 |
|
177 // Get type name by enumerator |
|
178 static QString typeName (LDObjectType type); |
|
179 |
|
180 // Returns a default-constructed LDObject by the given type |
|
181 static LDObject* getDefault (const LDObjectType type); |
|
182 |
|
183 // TODO: move this to LDDocument? |
|
184 static void moveObjects (LDObjectList objs, const bool up); |
|
185 |
|
186 // Get a description of a list of LDObjects |
|
187 static QString describeObjects (const LDObjectList& objs); |
133 static QString describeObjects (const LDObjectList& objs); |
188 static LDObject* fromID (int id); |
134 static LDObject* fromID (int id); |
189 LDPolygon* getPolygon(); |
135 static LDObject* getDefault (const LDObjectType type); |
190 bool isDestroyed() const { return m_isDestroyed; } |
136 static void moveObjects (LDObjectList objs, const bool up); // TODO: move this to LDDocument? |
191 |
137 static QString typeName (LDObjectType type); |
192 // TODO: make this private! |
|
193 QListWidgetItem* qObjListEntry; |
|
194 |
138 |
195 protected: |
139 protected: |
196 virtual ~LDObject(); |
140 virtual ~LDObject(); |
197 |
141 |
198 private: |
142 private: |
|
143 bool m_isHidden; |
|
144 bool m_isSelected; |
|
145 bool m_isDestroyed; |
|
146 LDObject* m_parent; |
|
147 LDDocument* m_document; |
|
148 qint32 m_id; |
|
149 LDColor m_color; |
|
150 QColor m_randomColor; |
199 Vertex m_coords[4]; |
151 Vertex m_coords[4]; |
200 bool m_isDestroyed; |
152 }; |
201 |
153 |
202 void chooseID(); |
|
203 }; |
|
204 |
|
205 // |
|
206 // Makes a new LDObject. This makes the shared pointer always use the custom |
|
207 // deleter so that all deletions go through finalDelete(); |
|
208 // |
|
209 template<typename T, typename... Args> |
154 template<typename T, typename... Args> |
210 T* LDSpawn (Args... args) |
155 T* LDSpawn (Args... args) |
211 { |
156 { |
212 static_assert (std::is_base_of<LDObject, T>::value, |
157 static_assert (std::is_base_of<LDObject, T>::value, |
213 "spawn may only be used with LDObject-derivatives"); |
158 "spawn may only be used with LDObject-derivatives"); |
231 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping |
176 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping |
232 // this class distinct in case I get new extension ideas. :) |
177 // this class distinct in case I get new extension ideas. :) |
233 // |
178 // |
234 class LDMatrixObject : public LDObject |
179 class LDMatrixObject : public LDObject |
235 { |
180 { |
236 PROPERTY (public, Matrix, transform, setTransform, CUSTOM_WRITE) |
|
237 Vertex m_position; |
181 Vertex m_position; |
238 |
182 |
239 public: |
183 public: |
240 LDMatrixObject (LDDocument* document = nullptr) : |
184 LDMatrixObject (LDDocument* document = nullptr); |
241 LDObject (document), |
185 LDMatrixObject (const Matrix& transform, const Vertex& pos, LDDocument* document = nullptr); |
242 m_position (Origin) {} |
186 |
243 |
187 const Vertex& position() const; |
244 LDMatrixObject (const Matrix& transform, const Vertex& pos, LDDocument* document = nullptr) : |
188 void setCoordinate (const Axis ax, double value); |
245 LDObject (document), |
|
246 m_transform (transform), |
|
247 m_position (pos) {} |
|
248 |
|
249 inline const Vertex& position() const |
|
250 { |
|
251 return m_position; |
|
252 } |
|
253 |
|
254 void setCoordinate (const Axis ax, double value) |
|
255 { |
|
256 Vertex v = position(); |
|
257 |
|
258 switch (ax) |
|
259 { |
|
260 case X: v.setX (value); break; |
|
261 case Y: v.setY (value); break; |
|
262 case Z: v.setZ (value); break; |
|
263 } |
|
264 |
|
265 setPosition (v); |
|
266 } |
|
267 |
|
268 void setPosition (const Vertex& a); |
189 void setPosition (const Vertex& a); |
|
190 const Matrix& transform() const; |
|
191 void setTransform (const Matrix& value); |
|
192 |
|
193 private: |
|
194 Matrix m_transform; |
269 }; |
195 }; |
270 |
196 |
271 // |
197 // |
272 // |
198 // |
273 // Represents a line in the LDraw file that could not be properly parsed. It is |
199 // Represents a line in the LDraw file that could not be properly parsed. It is |
487 }; |
413 }; |
488 |
414 |
489 // |
415 // |
490 // LDOverlay |
416 // LDOverlay |
491 // |
417 // |
492 // Overlay image meta, stored in the header of parts so as to preserve overlay |
418 // Overlay image meta, stored in the header of parts so as to preserve overlay information. |
493 // information. |
|
494 // |
419 // |
495 class LDOverlay : public LDObject |
420 class LDOverlay : public LDObject |
496 { |
421 { |
497 LDOBJ (Overlay) |
422 LDOBJ (Overlay) |
498 LDOBJ_NAME (overlay) |
423 LDOBJ_NAME (overlay) |
499 LDOBJ_VERTICES (0) |
424 LDOBJ_VERTICES (0) |
500 LDOBJ_UNCOLORED |
425 LDOBJ_UNCOLORED |
501 LDOBJ_NON_SCEMANTIC |
426 LDOBJ_NON_SCEMANTIC |
502 LDOBJ_NO_MATRIX |
427 LDOBJ_NO_MATRIX |
503 PROPERTY (public, int, camera, setCamera, STOCK_WRITE) |
428 |
504 PROPERTY (public, int, x, setX, STOCK_WRITE) |
429 public: |
505 PROPERTY (public, int, y, setY, STOCK_WRITE) |
430 int camera() const; |
506 PROPERTY (public, int, width, setWidth, STOCK_WRITE) |
431 QString fileName() const; |
507 PROPERTY (public, int, height, setHeight, STOCK_WRITE) |
432 int height() const; |
508 PROPERTY (public, QString, fileName, setFileName, STOCK_WRITE) |
433 void setCamera (int value); |
|
434 void setFileName (QString value); |
|
435 void setHeight (int value); |
|
436 void setWidth (int value); |
|
437 void setX (int value); |
|
438 void setY (int value); |
|
439 int width() const; |
|
440 int x() const; |
|
441 int y() const; |
|
442 |
|
443 private: |
|
444 int m_camera; |
|
445 int m_x; |
|
446 int m_y; |
|
447 int m_width; |
|
448 int m_height; |
|
449 QString m_fileName; |
509 }; |
450 }; |
510 |
451 |
511 // Other common LDraw stuff |
452 // Other common LDraw stuff |
512 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " |
453 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " |
513 "see CAreadme.txt"); |
454 "see CAreadme.txt"); |