37 virtual void invert() override; \ |
37 virtual void invert() override; \ |
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; } |
49 |
49 |
50 #define LDOBJ_SETMATRIX(V) public: virtual bool hasMatrix() const override { return V; } |
50 #define LDOBJ_SETMATRIX(V) public: virtual bool hasMatrix() const override { return V; } |
51 #define LDOBJ_HAS_MATRIX LDOBJ_SETMATRIX (true) |
51 #define LDOBJ_HAS_MATRIX LDOBJ_SETMATRIX(true) |
52 #define LDOBJ_NO_MATRIX LDOBJ_SETMATRIX (false) |
52 #define LDOBJ_NO_MATRIX LDOBJ_SETMATRIX(false) |
53 |
53 |
54 class QListWidgetItem; |
54 class QListWidgetItem; |
55 class LDSubfileReference; |
55 class LDSubfileReference; |
56 class LDDocument; |
56 class LDDocument; |
57 |
57 |
89 // sub-classes based on this enumerator. |
89 // sub-classes based on this enumerator. |
90 // |
90 // |
91 class LDObject |
91 class LDObject |
92 { |
92 { |
93 public: |
93 public: |
94 LDObject (LDDocument* document = nullptr); |
94 LDObject(LDDocument* document = nullptr); |
95 |
95 |
96 virtual QString asText() const = 0; // This object as LDraw code |
96 virtual QString asText() const = 0; // This object as LDraw code |
97 LDColor color() const; |
97 LDColor color() const; |
98 LDObject* createCopy() const; |
98 LDObject* createCopy() const; |
99 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
99 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
100 void deselect(); |
100 void deselect(); |
101 void destroy(); |
101 void destroy(); |
102 LDDocument* document() const; |
102 LDDocument* document() const; |
103 LDPolygon* getPolygon(); |
103 LDPolygon* getPolygon(); |
104 virtual void getVertices (QVector<Vertex>& verts) const; |
104 virtual void getVertices(QVector<Vertex>& verts) const; |
105 virtual bool hasMatrix() const = 0; // Does this object have a matrix and position? (see LDMatrixObject) |
105 virtual bool hasMatrix() const = 0; // Does this object have a matrix and position?(see LDMatrixObject) |
106 qint32 id() const; |
106 qint32 id() const; |
107 virtual void invert() = 0; // Inverts this object (winding is reversed) |
107 virtual void invert() = 0; // Inverts this object(winding is reversed) |
108 virtual bool isColored() const = 0; |
108 virtual bool isColored() const = 0; |
109 bool isDestroyed() const; |
109 bool isDestroyed() const; |
110 bool isHidden() const; |
110 bool isHidden() const; |
111 virtual bool isScemantic() const = 0; // Does this object have meaning in the part model? |
111 virtual bool isScemantic() const = 0; // Does this object have meaning in the part model? |
112 bool isSelected() const; |
112 bool isSelected() const; |
113 int lineNumber() const; |
113 int lineNumber() const; |
114 void move (Vertex vect); |
114 void move(Vertex vect); |
115 LDObject* next() const; |
115 LDObject* next() const; |
116 virtual int numVertices() const = 0; |
116 virtual int numVertices() const = 0; |
117 LDObject* previous() const; |
117 LDObject* previous() const; |
118 bool previousIsInvertnext (LDBfc*& ptr); |
118 bool previousIsInvertnext(LDBfc*& ptr); |
119 QColor randomColor() const; |
119 QColor randomColor() const; |
120 void replace (LDObject* other); |
120 void replace(LDObject* other); |
121 void replace (const LDObjectList& others); |
121 void replace(const LDObjectList& others); |
122 void select(); |
122 void select(); |
123 void setColor (LDColor color); |
123 void setColor(LDColor color); |
124 void setDocument (LDDocument* document); |
124 void setDocument(LDDocument* document); |
125 void setHidden (bool value); |
125 void setHidden(bool value); |
126 void setVertex (int i, const Vertex& vert); |
126 void setVertex(int i, const Vertex& vert); |
127 void swap (LDObject* other); |
127 void swap(LDObject* other); |
128 LDObject* topLevelParent(); |
128 LDObject* topLevelParent(); |
129 virtual LDObjectType type() const = 0; |
129 virtual LDObjectType type() const = 0; |
130 virtual QString typeName() const = 0; |
130 virtual QString typeName() const = 0; |
131 const Vertex& vertex (int i) const; |
131 const Vertex& vertex(int i) const; |
132 |
132 |
133 static QString describeObjects (const LDObjectList& objs); |
133 static QString describeObjects(const LDObjectList& objs); |
134 static LDObject* fromID (int id); |
134 static LDObject* fromID(int id); |
135 static LDObject* getDefault (const LDObjectType type); |
135 static LDObject* getDefault(const LDObjectType type); |
136 static void moveObjects (LDObjectList objs, const bool up); // TODO: move this to LDDocument? |
136 static void moveObjects(LDObjectList objs, const bool up); // TODO: move this to LDDocument? |
137 static QString typeName (LDObjectType type); |
137 static QString typeName(LDObjectType type); |
138 |
138 |
139 protected: |
139 protected: |
140 virtual ~LDObject(); |
140 virtual ~LDObject(); |
141 |
141 |
142 private: |
142 private: |
150 QColor m_randomColor; |
150 QColor m_randomColor; |
151 Vertex m_coords[4]; |
151 Vertex m_coords[4]; |
152 }; |
152 }; |
153 |
153 |
154 template<typename T, typename... Args> |
154 template<typename T, typename... Args> |
155 T* LDSpawn (Args... args) |
155 T* LDSpawn(Args... args) |
156 { |
156 { |
157 static_assert (std::is_base_of<LDObject, T>::value, |
157 static_assert(std::is_base_of<LDObject, T>::value, |
158 "spawn may only be used with LDObject-derivatives"); |
158 "spawn may only be used with LDObject-derivatives"); |
159 T* result = new T (args..., nullptr); |
159 T* result = new T(args..., nullptr); |
160 |
160 |
161 // Set default color. Relying on virtual functions, this cannot be done in the c-tor. |
161 // Set default color. Relying on virtual functions, this cannot be done in the c-tor. |
162 // TODO: store -1 as the default color |
162 // TODO: store -1 as the default color |
163 if (result->isColored()) |
163 if (result->isColored()) |
164 result->setColor (result->defaultColor()); |
164 result->setColor(result->defaultColor()); |
165 |
165 |
166 return result; |
166 return result; |
167 } |
167 } |
168 |
168 |
169 // |
169 // |
179 class LDMatrixObject : public LDObject |
179 class LDMatrixObject : public LDObject |
180 { |
180 { |
181 Vertex m_position; |
181 Vertex m_position; |
182 |
182 |
183 public: |
183 public: |
184 LDMatrixObject (LDDocument* document = nullptr); |
184 LDMatrixObject(LDDocument* document = nullptr); |
185 LDMatrixObject (const Matrix& transform, const Vertex& pos, LDDocument* document = nullptr); |
185 LDMatrixObject(const Matrix& transform, const Vertex& pos, LDDocument* document = nullptr); |
186 |
186 |
187 const Vertex& position() const; |
187 const Vertex& position() const; |
188 void setCoordinate (const Axis ax, double value); |
188 void setCoordinate(const Axis ax, double value); |
189 void setPosition (const Vertex& a); |
189 void setPosition(const Vertex& a); |
190 const Matrix& transform() const; |
190 const Matrix& transform() const; |
191 void setTransform (const Matrix& value); |
191 void setTransform(const Matrix& value); |
192 |
192 |
193 private: |
193 private: |
194 Matrix m_transform; |
194 Matrix m_transform; |
195 }; |
195 }; |
196 |
196 |
197 // |
197 // |
198 // |
198 // |
199 // 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 |
200 // represented by a (!) ERROR in the code view. It exists for the purpose of |
200 // represented by a(!) ERROR in the code view. It exists for the purpose of |
201 // allowing garbage lines be debugged and corrected within LDForge. |
201 // allowing garbage lines be debugged and corrected within LDForge. |
202 // |
202 // |
203 class LDError : public LDObject |
203 class LDError : public LDObject |
204 { |
204 { |
205 LDOBJ (Error) |
205 LDOBJ(Error) |
206 LDOBJ_NAME (error) |
206 LDOBJ_NAME(error) |
207 LDOBJ_VERTICES (0) |
207 LDOBJ_VERTICES(0) |
208 LDOBJ_UNCOLORED |
208 LDOBJ_UNCOLORED |
209 LDOBJ_SCEMANTIC |
209 LDOBJ_SCEMANTIC |
210 LDOBJ_NO_MATRIX |
210 LDOBJ_NO_MATRIX |
211 |
211 |
212 public: |
212 public: |
213 LDError (QString contents, QString reason, LDDocument* document = nullptr); |
213 LDError(QString contents, QString reason, LDDocument* document = nullptr); |
214 QString reason() const; |
214 QString reason() const; |
215 QString contents() const; |
215 QString contents() const; |
216 QString fileReferenced() const; |
216 QString fileReferenced() const; |
217 void setFileReferenced (QString value); |
217 void setFileReferenced(QString value); |
218 |
218 |
219 private: |
219 private: |
220 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? |
220 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? |
221 QString m_contents; // The LDraw code that was being parsed |
221 QString m_contents; // The LDraw code that was being parsed |
222 QString m_reason; |
222 QString m_reason; |
280 }; |
280 }; |
281 |
281 |
282 class LDBfc : public LDObject |
282 class LDBfc : public LDObject |
283 { |
283 { |
284 public: |
284 public: |
285 LDOBJ (Bfc) |
285 LDOBJ(Bfc) |
286 LDOBJ_NAME (bfc) |
286 LDOBJ_NAME(bfc) |
287 LDOBJ_VERTICES (0) |
287 LDOBJ_VERTICES(0) |
288 LDOBJ_UNCOLORED |
288 LDOBJ_UNCOLORED |
289 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } |
289 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } |
290 LDOBJ_NO_MATRIX |
290 LDOBJ_NO_MATRIX |
291 |
291 |
292 public: |
292 public: |
293 LDBfc (const BfcStatement type, LDDocument* document = nullptr); |
293 LDBfc(const BfcStatement type, LDDocument* document = nullptr); |
294 |
294 |
295 BfcStatement statement() const; |
295 BfcStatement statement() const; |
296 void setStatement (BfcStatement value); |
296 void setStatement(BfcStatement value); |
297 QString statementToString() const; |
297 QString statementToString() const; |
298 |
298 |
299 static QString statementToString (BfcStatement statement); |
299 static QString statementToString(BfcStatement statement); |
300 |
300 |
301 private: |
301 private: |
302 BfcStatement m_statement; |
302 BfcStatement m_statement; |
303 }; |
303 }; |
304 |
304 |
307 // |
307 // |
308 // Represents a single code-1 subfile reference. |
308 // Represents a single code-1 subfile reference. |
309 // |
309 // |
310 class LDSubfileReference : public LDMatrixObject |
310 class LDSubfileReference : public LDMatrixObject |
311 { |
311 { |
312 LDOBJ (SubfileReference) |
312 LDOBJ(SubfileReference) |
313 LDOBJ_NAME (subfilereference) |
313 LDOBJ_NAME(subfilereference) |
314 LDOBJ_VERTICES (0) |
314 LDOBJ_VERTICES(0) |
315 LDOBJ_COLORED |
315 LDOBJ_COLORED |
316 LDOBJ_DEFAULTCOLOR (MainColor) |
316 LDOBJ_DEFAULTCOLOR(MainColor) |
317 LDOBJ_SCEMANTIC |
317 LDOBJ_SCEMANTIC |
318 LDOBJ_HAS_MATRIX |
318 LDOBJ_HAS_MATRIX |
319 |
319 |
320 public: |
320 public: |
321 // Inlines this subfile. |
321 // Inlines this subfile. |
322 LDDocument* fileInfo() const; |
322 LDDocument* fileInfo() const; |
323 virtual void getVertices (QVector<Vertex>& verts) const override; |
323 virtual void getVertices(QVector<Vertex>& verts) const override; |
324 LDObjectList inlineContents (bool deep, bool render); |
324 LDObjectList inlineContents(bool deep, bool render); |
325 QList<LDPolygon> inlinePolygons(); |
325 QList<LDPolygon> inlinePolygons(); |
326 void setFileInfo (LDDocument* fileInfo); |
326 void setFileInfo(LDDocument* fileInfo); |
327 |
327 |
328 private: |
328 private: |
329 LDDocument* m_fileInfo; |
329 LDDocument* m_fileInfo; |
330 }; |
330 }; |
331 |
331 |
334 // |
334 // |
335 // Represents a single code-2 line in the LDraw code file. |
335 // Represents a single code-2 line in the LDraw code file. |
336 // |
336 // |
337 class LDLine : public LDObject |
337 class LDLine : public LDObject |
338 { |
338 { |
339 LDOBJ (Line) |
339 LDOBJ(Line) |
340 LDOBJ_NAME (line) |
340 LDOBJ_NAME(line) |
341 LDOBJ_VERTICES (2) |
341 LDOBJ_VERTICES(2) |
342 LDOBJ_COLORED |
342 LDOBJ_COLORED |
343 LDOBJ_DEFAULTCOLOR (EdgeColor) |
343 LDOBJ_DEFAULTCOLOR(EdgeColor) |
344 LDOBJ_SCEMANTIC |
344 LDOBJ_SCEMANTIC |
345 LDOBJ_NO_MATRIX |
345 LDOBJ_NO_MATRIX |
346 |
346 |
347 public: |
347 public: |
348 LDLine (Vertex v1, Vertex v2, LDDocument* document = nullptr); |
348 LDLine(Vertex v1, Vertex v2, LDDocument* document = nullptr); |
349 }; |
349 }; |
350 |
350 |
351 // |
351 // |
352 // LDCondLine |
352 // LDCondLine |
353 // |
353 // |
354 // Represents a single code-5 conditional line. |
354 // Represents a single code-5 conditional line. |
355 // |
355 // |
356 class LDCondLine : public LDLine |
356 class LDCondLine : public LDLine |
357 { |
357 { |
358 LDOBJ (CondLine) |
358 LDOBJ(CondLine) |
359 LDOBJ_NAME (condline) |
359 LDOBJ_NAME(condline) |
360 LDOBJ_VERTICES (4) |
360 LDOBJ_VERTICES(4) |
361 LDOBJ_COLORED |
361 LDOBJ_COLORED |
362 LDOBJ_DEFAULTCOLOR (EdgeColor) |
362 LDOBJ_DEFAULTCOLOR(EdgeColor) |
363 LDOBJ_SCEMANTIC |
363 LDOBJ_SCEMANTIC |
364 LDOBJ_NO_MATRIX |
364 LDOBJ_NO_MATRIX |
365 |
365 |
366 public: |
366 public: |
367 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
367 LDCondLine(const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
368 LDLine* toEdgeLine(); |
368 LDLine* toEdgeLine(); |
369 }; |
369 }; |
370 |
370 |
371 // |
371 // |
372 // LDTriangle |
372 // LDTriangle |
375 // and v2 contain the end-points of this triangle. dColor is the color the |
375 // and v2 contain the end-points of this triangle. dColor is the color the |
376 // triangle is colored with. |
376 // triangle is colored with. |
377 // |
377 // |
378 class LDTriangle : public LDObject |
378 class LDTriangle : public LDObject |
379 { |
379 { |
380 LDOBJ (Triangle) |
380 LDOBJ(Triangle) |
381 LDOBJ_NAME (triangle) |
381 LDOBJ_NAME(triangle) |
382 LDOBJ_VERTICES (3) |
382 LDOBJ_VERTICES(3) |
383 LDOBJ_COLORED |
383 LDOBJ_COLORED |
384 LDOBJ_DEFAULTCOLOR (MainColor) |
384 LDOBJ_DEFAULTCOLOR(MainColor) |
385 LDOBJ_SCEMANTIC |
385 LDOBJ_SCEMANTIC |
386 LDOBJ_NO_MATRIX |
386 LDOBJ_NO_MATRIX |
387 |
387 |
388 public: |
388 public: |
389 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr); |
389 LDTriangle(Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr); |
390 }; |
390 }; |
391 |
391 |
392 // |
392 // |
393 // LDQuad |
393 // LDQuad |
394 // |
394 // |
395 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
395 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
396 // of the quad, dColor is the color used for the quad. |
396 // of the quad, dColor is the color used for the quad. |
397 // |
397 // |
398 class LDQuad : public LDObject |
398 class LDQuad : public LDObject |
399 { |
399 { |
400 LDOBJ (Quad) |
400 LDOBJ(Quad) |
401 LDOBJ_NAME (quad) |
401 LDOBJ_NAME(quad) |
402 LDOBJ_VERTICES (4) |
402 LDOBJ_VERTICES(4) |
403 LDOBJ_COLORED |
403 LDOBJ_COLORED |
404 LDOBJ_DEFAULTCOLOR (MainColor) |
404 LDOBJ_DEFAULTCOLOR(MainColor) |
405 LDOBJ_SCEMANTIC |
405 LDOBJ_SCEMANTIC |
406 LDOBJ_NO_MATRIX |
406 LDOBJ_NO_MATRIX |
407 |
407 |
408 public: |
408 public: |
409 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document = nullptr); |
409 LDQuad(const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document = nullptr); |
410 |
410 |
411 // Split this quad into two triangles |
411 // Split this quad into two triangles |
412 QList<LDTriangle*> splitToTriangles(); |
412 QList<LDTriangle*> splitToTriangles(); |
413 }; |
413 }; |
414 |
414 |
417 // |
417 // |
418 // Overlay image meta, stored in the header of parts so as to preserve overlay information. |
418 // Overlay image meta, stored in the header of parts so as to preserve overlay information. |
419 // |
419 // |
420 class LDOverlay : public LDObject |
420 class LDOverlay : public LDObject |
421 { |
421 { |
422 LDOBJ (Overlay) |
422 LDOBJ(Overlay) |
423 LDOBJ_NAME (overlay) |
423 LDOBJ_NAME(overlay) |
424 LDOBJ_VERTICES (0) |
424 LDOBJ_VERTICES(0) |
425 LDOBJ_UNCOLORED |
425 LDOBJ_UNCOLORED |
426 LDOBJ_NON_SCEMANTIC |
426 LDOBJ_NON_SCEMANTIC |
427 LDOBJ_NO_MATRIX |
427 LDOBJ_NO_MATRIX |
428 |
428 |
429 public: |
429 public: |
430 int camera() const; |
430 int camera() const; |
431 QString fileName() const; |
431 QString fileName() const; |
432 int height() const; |
432 int height() const; |
433 void setCamera (int value); |
433 void setCamera(int value); |
434 void setFileName (QString value); |
434 void setFileName(QString value); |
435 void setHeight (int value); |
435 void setHeight(int value); |
436 void setWidth (int value); |
436 void setWidth(int value); |
437 void setX (int value); |
437 void setX(int value); |
438 void setY (int value); |
438 void setY(int value); |
439 int width() const; |
439 int width() const; |
440 int x() const; |
440 int x() const; |
441 int y() const; |
441 int y() const; |
442 |
442 |
443 private: |
443 private: |
449 QString m_fileName; |
449 QString m_fileName; |
450 }; |
450 }; |
451 |
451 |
452 class LDBezierCurve : public LDObject |
452 class LDBezierCurve : public LDObject |
453 { |
453 { |
454 LDOBJ (BezierCurve) |
454 LDOBJ(BezierCurve) |
455 LDOBJ_NAME (beziercurve) |
455 LDOBJ_NAME(beziercurve) |
456 LDOBJ_VERTICES (4) |
456 LDOBJ_VERTICES(4) |
457 LDOBJ_COLORED |
457 LDOBJ_COLORED |
458 LDOBJ_DEFAULTCOLOR (EdgeColor) |
458 LDOBJ_DEFAULTCOLOR(EdgeColor) |
459 LDOBJ_SCEMANTIC |
459 LDOBJ_SCEMANTIC |
460 LDOBJ_NO_MATRIX |
460 LDOBJ_NO_MATRIX |
461 |
461 |
462 public: |
462 public: |
463 LDBezierCurve (const Vertex& v0, const Vertex& v1, |
463 LDBezierCurve(const Vertex& v0, const Vertex& v1, |
464 const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
464 const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
465 Vertex pointAt (qreal t) const; |
465 Vertex pointAt(qreal t) const; |
466 LDObjectList rasterize (int segments = 0); |
466 LDObjectList rasterize(int segments = 0); |
467 QVector<LDPolygon> rasterizePolygons (int segments = 0); |
467 QVector<LDPolygon> rasterizePolygons(int segments = 0); |
468 }; |
468 }; |
469 |
469 |
470 // Other common LDraw stuff |
470 // Other common LDraw stuff |
471 static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " |
471 static const QString CALicenseText("!LICENSE Redistributable under CCAL version 2.0 : " |
472 "see CAreadme.txt"); |
472 "see CAreadme.txt"); |
473 |
473 |
474 enum |
474 enum |
475 { |
475 { |
476 LowResolution = 16, |
476 LowResolution = 16, |