35 \ |
35 \ |
36 virtual QString asText() const override; \ |
36 virtual QString asText() const override; \ |
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; } |
|
41 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } |
40 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } |
42 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
41 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
43 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) LDOBJ_DEFAULTCOLOR (MainColor) |
42 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) LDOBJ_DEFAULTCOLOR (MainColor) |
44 #define LDOBJ_DEFAULTCOLOR(V) public: virtual LDColor defaultColor() const override { return (V); } |
43 #define LDOBJ_DEFAULTCOLOR(V) public: virtual LDColor defaultColor() const override { return (V); } |
45 |
44 |
97 LDObject* createCopy() const; |
95 LDObject* createCopy() const; |
98 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
96 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
99 void deselect(); |
97 void deselect(); |
100 void destroy(); |
98 void destroy(); |
101 LDDocument* document() const; |
99 LDDocument* document() const; |
102 LDPolygon* getPolygon(); |
|
103 virtual void getVertices (QVector<Vertex>& verts) const; |
100 virtual void getVertices (QVector<Vertex>& verts) const; |
104 virtual bool hasMatrix() const = 0; // Does this object have a matrix and position? (see LDMatrixObject) |
101 virtual bool hasMatrix() const { return false; } |
|
102 virtual bool hasVertices() const { return false; } |
105 qint32 id() const; |
103 qint32 id() const; |
106 virtual void invert() = 0; // Inverts this object (winding is reversed) |
104 virtual void invert() = 0; // Inverts this object (winding is reversed) |
107 virtual bool isColored() const = 0; |
105 virtual bool isColored() const = 0; |
108 bool isDestroyed() const; |
106 bool isDestroyed() const; |
109 bool isHidden() const; |
107 bool isHidden() const; |
110 virtual bool isScemantic() const = 0; // Does this object have meaning in the part model? |
108 virtual bool isScemantic() const = 0; // Does this object have meaning in the part model? |
111 bool isSelected() const; |
109 bool isSelected() const; |
112 int lineNumber() const; |
110 int lineNumber() const; |
113 void move (Vertex vect); |
111 void move (Vertex vect); |
114 LDObject* next() const; |
112 LDObject* next() const; |
115 virtual int numVertices() const = 0; |
|
116 LDObject* previous() const; |
113 LDObject* previous() const; |
117 bool previousIsInvertnext (LDBfc*& ptr); |
114 bool previousIsInvertnext (LDBfc*& ptr); |
118 QColor randomColor() const; |
115 QColor randomColor() const; |
119 void replace (LDObject* other); |
116 void replace (LDObject* other); |
120 void select(); |
117 void select(); |
121 void setColor (LDColor color); |
118 void setColor (LDColor color); |
122 void setDocument (LDDocument* document); |
119 void setDocument (LDDocument* document); |
123 void setHidden (bool value); |
120 void setHidden (bool value); |
124 void setVertex (int i, const Vertex& vert); |
|
125 void swap (LDObject* other); |
121 void swap (LDObject* other); |
126 LDObject* topLevelParent(); |
122 virtual void transform (const Matrix& transformationMatrix, const Vertex& position); |
127 virtual LDObjectType type() const = 0; |
123 virtual LDObjectType type() const = 0; |
128 virtual QString typeName() const = 0; |
124 virtual QString typeName() const = 0; |
129 const Vertex& vertex (int i) const; |
|
130 |
125 |
131 static QString describeObjects (const LDObjectList& objs); |
126 static QString describeObjects (const LDObjectList& objs); |
132 static LDObject* fromID (int id); |
127 static LDObject* fromID (int id); |
133 static LDObject* getDefault (const LDObjectType type); |
128 static LDObject* getDefault (const LDObjectType type); |
134 static void moveObjects (LDObjectList objs, const bool up); // TODO: move this to LDDocument? |
129 static void moveObjects (LDObjectList objs, const bool up); // TODO: move this to LDDocument? |
174 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping |
167 // matrix as well. Even though right now only LDSubfile uses this, I'm keeping |
175 // this class distinct in case I get new extension ideas. :) |
168 // this class distinct in case I get new extension ideas. :) |
176 // |
169 // |
177 class LDMatrixObject : public LDObject |
170 class LDMatrixObject : public LDObject |
178 { |
171 { |
179 Vertex m_position; |
|
180 |
|
181 public: |
172 public: |
182 LDMatrixObject (LDDocument* document = nullptr); |
173 LDMatrixObject (LDDocument* document = nullptr); |
183 LDMatrixObject (const Matrix& transform, const Vertex& pos, LDDocument* document = nullptr); |
174 LDMatrixObject (const Matrix& transformationMatrix, const Vertex& position, LDDocument* document = nullptr); |
184 |
175 |
|
176 virtual bool hasMatrix() const { return true; } |
185 const Vertex& position() const; |
177 const Vertex& position() const; |
186 void setCoordinate (const Axis ax, double value); |
178 void setCoordinate (const Axis ax, double value); |
187 void setPosition (const Vertex& a); |
179 void setPosition (const Vertex& a); |
188 const Matrix& transform() const; |
180 void setTransformationMatrix (const Matrix& value); |
189 void setTransform (const Matrix& value); |
181 virtual void transform (const Matrix& transformationMatrix, const Vertex& position); |
190 |
182 const Matrix& transformationMatrix() const; |
191 private: |
183 |
192 Matrix m_transform; |
184 private: |
|
185 Vertex m_position; |
|
186 Matrix m_transformationMatrix; |
|
187 }; |
|
188 |
|
189 class LDVertexObject : public LDObject |
|
190 { |
|
191 public: |
|
192 LDVertexObject (LDDocument* document = nullptr); |
|
193 |
|
194 LDPolygon* getPolygon(); |
|
195 virtual void getVertices (QVector<Vertex>& verts) const; |
|
196 virtual bool hasVertices() const { return true; } |
|
197 virtual int numVertices() const = 0; |
|
198 void setVertex (int i, const Vertex& vert); |
|
199 virtual void transform (const Matrix& transformationMatrix, const Vertex& position); |
|
200 const Vertex& vertex (int i) const; |
|
201 QSet<Vertex> vertexSet() const; |
|
202 |
|
203 private: |
|
204 Vertex m_coordinates[4]; |
193 }; |
205 }; |
194 |
206 |
195 // |
207 // |
196 // |
208 // |
197 // Represents a line in the LDraw file that could not be properly parsed. It is |
209 // Represents a line in the LDraw file that could not be properly parsed. It is |
200 // |
212 // |
201 class LDError : public LDObject |
213 class LDError : public LDObject |
202 { |
214 { |
203 LDOBJ (Error) |
215 LDOBJ (Error) |
204 LDOBJ_NAME (error) |
216 LDOBJ_NAME (error) |
205 LDOBJ_VERTICES (0) |
|
206 LDOBJ_UNCOLORED |
217 LDOBJ_UNCOLORED |
207 LDOBJ_SCEMANTIC |
218 LDOBJ_SCEMANTIC |
208 LDOBJ_NO_MATRIX |
|
209 |
|
210 public: |
219 public: |
211 LDError (QString contents, QString reason, LDDocument* document = nullptr); |
220 LDError (QString contents, QString reason, LDDocument* document = nullptr); |
212 QString reason() const; |
221 |
213 QString contents() const; |
222 QString contents() const; |
214 QString fileReferenced() const; |
223 QString fileReferenced() const; |
|
224 QString reason() const; |
215 void setFileReferenced (QString value); |
225 void setFileReferenced (QString value); |
216 |
226 |
217 private: |
227 private: |
218 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? |
228 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? |
219 QString m_contents; // The LDraw code that was being parsed |
229 QString m_contents; // The LDraw code that was being parsed |
280 class LDBfc : public LDObject |
286 class LDBfc : public LDObject |
281 { |
287 { |
282 public: |
288 public: |
283 LDOBJ (Bfc) |
289 LDOBJ (Bfc) |
284 LDOBJ_NAME (bfc) |
290 LDOBJ_NAME (bfc) |
285 LDOBJ_VERTICES (0) |
|
286 LDOBJ_UNCOLORED |
291 LDOBJ_UNCOLORED |
287 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } |
292 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } |
288 LDOBJ_NO_MATRIX |
|
289 |
293 |
290 public: |
294 public: |
291 LDBfc (const BfcStatement type, LDDocument* document = nullptr); |
295 LDBfc (const BfcStatement type, LDDocument* document = nullptr); |
292 |
296 |
|
297 void setStatement (BfcStatement value); |
293 BfcStatement statement() const; |
298 BfcStatement statement() const; |
294 void setStatement (BfcStatement value); |
|
295 QString statementToString() const; |
299 QString statementToString() const; |
296 |
300 |
297 static QString statementToString (BfcStatement statement); |
301 static QString statementToString (BfcStatement statement); |
298 |
302 |
299 private: |
303 private: |
353 // |
354 // |
354 class LDCondLine : public LDLine |
355 class LDCondLine : public LDLine |
355 { |
356 { |
356 LDOBJ (CondLine) |
357 LDOBJ (CondLine) |
357 LDOBJ_NAME (condline) |
358 LDOBJ_NAME (condline) |
358 LDOBJ_VERTICES (4) |
|
359 LDOBJ_COLORED |
359 LDOBJ_COLORED |
360 LDOBJ_DEFAULTCOLOR (EdgeColor) |
360 LDOBJ_DEFAULTCOLOR (EdgeColor) |
361 LDOBJ_SCEMANTIC |
361 LDOBJ_SCEMANTIC |
362 LDOBJ_NO_MATRIX |
|
363 |
362 |
364 public: |
363 public: |
365 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
364 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
366 LDLine* toEdgeLine(); |
365 LDLine* toEdgeLine(); |
|
366 int numVertices() const override { return 4; } |
367 }; |
367 }; |
368 |
368 |
369 // |
369 // |
370 // LDTriangle |
370 // LDTriangle |
371 // |
371 // |
372 // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 |
372 // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 |
373 // and v2 contain the end-points of this triangle. dColor is the color the |
373 // and v2 contain the end-points of this triangle. dColor is the color the |
374 // triangle is colored with. |
374 // triangle is colored with. |
375 // |
375 // |
376 class LDTriangle : public LDObject |
376 class LDTriangle : public LDVertexObject |
377 { |
377 { |
378 LDOBJ (Triangle) |
378 LDOBJ (Triangle) |
379 LDOBJ_NAME (triangle) |
379 LDOBJ_NAME (triangle) |
380 LDOBJ_VERTICES (3) |
|
381 LDOBJ_COLORED |
380 LDOBJ_COLORED |
382 LDOBJ_DEFAULTCOLOR (MainColor) |
381 LDOBJ_DEFAULTCOLOR (MainColor) |
383 LDOBJ_SCEMANTIC |
382 LDOBJ_SCEMANTIC |
384 LDOBJ_NO_MATRIX |
|
385 |
383 |
386 public: |
384 public: |
387 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr); |
385 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr); |
|
386 int numVertices() const override { return 3; } |
388 }; |
387 }; |
389 |
388 |
390 // |
389 // |
391 // LDQuad |
390 // LDQuad |
392 // |
391 // |
393 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
392 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points |
394 // of the quad, dColor is the color used for the quad. |
393 // of the quad, dColor is the color used for the quad. |
395 // |
394 // |
396 class LDQuad : public LDObject |
395 class LDQuad : public LDVertexObject |
397 { |
396 { |
398 LDOBJ (Quad) |
397 LDOBJ (Quad) |
399 LDOBJ_NAME (quad) |
398 LDOBJ_NAME (quad) |
400 LDOBJ_VERTICES (4) |
|
401 LDOBJ_COLORED |
399 LDOBJ_COLORED |
402 LDOBJ_DEFAULTCOLOR (MainColor) |
400 LDOBJ_DEFAULTCOLOR (MainColor) |
403 LDOBJ_SCEMANTIC |
401 LDOBJ_SCEMANTIC |
404 LDOBJ_NO_MATRIX |
|
405 |
402 |
406 public: |
403 public: |
407 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document = nullptr); |
404 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document = nullptr); |
408 |
405 |
409 // Split this quad into two triangles |
406 // Split this quad into two triangles |
410 QList<LDTriangle*> splitToTriangles(); |
407 QList<LDTriangle*> splitToTriangles(); |
|
408 int numVertices() const override { return 4; } |
411 }; |
409 }; |
412 |
410 |
413 // |
411 // |
414 // LDOverlay |
412 // LDOverlay |
415 // |
413 // |