src/ldObject.h

changeset 996
9ecc878c7dea
parent 995
7986584e7498
equal deleted inserted replaced
995:7986584e7498 996:9ecc878c7dea
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
52 #define LDOBJ_NO_MATRIX LDOBJ_SETMATRIX (false) 51 #define LDOBJ_NO_MATRIX LDOBJ_SETMATRIX (false)
53 52
54 class QListWidgetItem; 53 class QListWidgetItem;
55 class LDSubfile; 54 class LDSubfile;
56 class LDDocument; 55 class LDDocument;
57
58 class LDBfc; 56 class LDBfc;
59 57
60 // 58 //
61 // Object type codes. 59 // Object type codes.
62 // 60 //
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?
139 134
140 private: 135 private:
141 bool m_isHidden; 136 bool m_isHidden;
142 bool m_isSelected; 137 bool m_isSelected;
143 bool m_isDestroyed; 138 bool m_isDestroyed;
144 LDObject* m_parent;
145 LDDocument* m_document; 139 LDDocument* m_document;
146 qint32 m_id; 140 qint32 m_id;
147 LDColor m_color; 141 LDColor m_color;
148 QColor m_randomColor; 142 QColor m_randomColor;
149 Vertex m_coords[4];
150 }; 143 };
151 144
152 template<typename T, typename... Args> 145 template<typename T, typename... Args>
153 T* LDSpawn (Args... args) 146 T* LDSpawn (Args... args)
154 { 147 {
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
226 // 236 //
227 class LDEmpty : public LDObject 237 class LDEmpty : public LDObject
228 { 238 {
229 LDOBJ (Empty) 239 LDOBJ (Empty)
230 LDOBJ_NAME (empty) 240 LDOBJ_NAME (empty)
231 LDOBJ_VERTICES (0)
232 LDOBJ_UNCOLORED 241 LDOBJ_UNCOLORED
233 LDOBJ_NON_SCEMANTIC 242 LDOBJ_NON_SCEMANTIC
234 LDOBJ_NO_MATRIX
235 }; 243 };
236 244
237 // 245 //
238 // 246 //
239 // Represents a code-0 comment in the LDraw code file. 247 // Represents a code-0 comment in the LDraw code file.
240 // 248 //
241 class LDComment : public LDObject 249 class LDComment : public LDObject
242 { 250 {
243 LDOBJ (Comment) 251 LDOBJ (Comment)
244 LDOBJ_NAME (comment) 252 LDOBJ_NAME (comment)
245 LDOBJ_VERTICES (0)
246 LDOBJ_UNCOLORED 253 LDOBJ_UNCOLORED
247 LDOBJ_NON_SCEMANTIC 254 LDOBJ_NON_SCEMANTIC
248 LDOBJ_NO_MATRIX
249 255
250 public: 256 public:
251 LDComment (QString text, LDDocument* document = nullptr); 257 LDComment (QString text, LDDocument* document = nullptr);
252 QString text() const; 258 QString text() const;
253 void setText (QString value); 259 void setText (QString value);
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:
307 // 311 //
308 class LDSubfile : public LDMatrixObject 312 class LDSubfile : public LDMatrixObject
309 { 313 {
310 LDOBJ (Subfile) 314 LDOBJ (Subfile)
311 LDOBJ_NAME (subfile) 315 LDOBJ_NAME (subfile)
312 LDOBJ_VERTICES (0)
313 LDOBJ_COLORED 316 LDOBJ_COLORED
314 LDOBJ_DEFAULTCOLOR (MainColor) 317 LDOBJ_DEFAULTCOLOR (MainColor)
315 LDOBJ_SCEMANTIC 318 LDOBJ_SCEMANTIC
316 LDOBJ_HAS_MATRIX
317 319
318 public: 320 public:
319 // Inlines this subfile. 321 // Inlines this subfile.
320 LDDocument* fileInfo() const; 322 LDDocument* fileInfo() const;
321 virtual void getVertices (QVector<Vertex>& verts) const override; 323 virtual void getVertices (QVector<Vertex>& verts) const override;
330 // 332 //
331 // LDLine 333 // LDLine
332 // 334 //
333 // Represents a single code-2 line in the LDraw code file. 335 // Represents a single code-2 line in the LDraw code file.
334 // 336 //
335 class LDLine : public LDObject 337 class LDLine : public LDVertexObject
336 { 338 {
337 LDOBJ (Line) 339 LDOBJ (Line)
338 LDOBJ_NAME (line) 340 LDOBJ_NAME (line)
339 LDOBJ_VERTICES (2)
340 LDOBJ_COLORED 341 LDOBJ_COLORED
341 LDOBJ_DEFAULTCOLOR (EdgeColor) 342 LDOBJ_DEFAULTCOLOR (EdgeColor)
342 LDOBJ_SCEMANTIC 343 LDOBJ_SCEMANTIC
343 LDOBJ_NO_MATRIX
344 344
345 public: 345 public:
346 LDLine (Vertex v1, Vertex v2, LDDocument* document = nullptr); 346 LDLine (Vertex v1, Vertex v2, LDDocument* document = nullptr);
347 int numVertices() const override { return 2; }
347 }; 348 };
348 349
349 // 350 //
350 // LDCondLine 351 // LDCondLine
351 // 352 //
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 //
417 // 415 //
418 class LDOverlay : public LDObject 416 class LDOverlay : public LDObject
419 { 417 {
420 LDOBJ (Overlay) 418 LDOBJ (Overlay)
421 LDOBJ_NAME (overlay) 419 LDOBJ_NAME (overlay)
422 LDOBJ_VERTICES (0)
423 LDOBJ_UNCOLORED 420 LDOBJ_UNCOLORED
424 LDOBJ_NON_SCEMANTIC 421 LDOBJ_NON_SCEMANTIC
425 LDOBJ_NO_MATRIX
426 422
427 public: 423 public:
428 int camera() const; 424 int camera() const;
429 QString fileName() const; 425 QString fileName() const;
430 int height() const; 426 int height() const;

mercurial