src/ldObject.h

changeset 1081
47cde4087cc5
parent 1080
6dac2d52bd9a
child 1082
1738bdaf36d6
equal deleted inserted replaced
1080:6dac2d52bd9a 1081:47cde4087cc5
26 class Model; 26 class Model;
27 27
28 #define LDOBJ(T) \ 28 #define LDOBJ(T) \
29 public: \ 29 public: \
30 static constexpr LDObjectType SubclassType = OBJ_##T; \ 30 static constexpr LDObjectType SubclassType = OBJ_##T; \
31 LD##T (Model* model = nullptr); \
32 \ 31 \
33 virtual LDObjectType type() const override \ 32 virtual LDObjectType type() const override \
34 { \ 33 { \
35 return OBJ_##T; \ 34 return OBJ_##T; \
36 } \ 35 } \
37 \ 36 \
38 virtual QString asText() const override; \ 37 virtual QString asText() const override; \
39 virtual void invert() override; \ 38 virtual void invert() override; \
39 protected: \
40 friend class Model; \
41 LD##T (Model* model = nullptr); \
40 42
41 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; } 43 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; }
42 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; } 44 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; }
43 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } 45 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; }
44 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) 46 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true)
93 class LDObject : public QObject 95 class LDObject : public QObject
94 { 96 {
95 Q_OBJECT 97 Q_OBJECT
96 98
97 public: 99 public:
98 LDObject (Model* model = nullptr);
99
100 virtual QString asText() const = 0; // This object as LDraw code 100 virtual QString asText() const = 0; // This object as LDraw code
101 LDColor color() const; 101 LDColor color() const;
102 virtual LDColor defaultColor() const = 0; // What color does the object default to? 102 virtual LDColor defaultColor() const = 0; // What color does the object default to?
103 Model* model() const; 103 Model* model() const;
104 LDPolygon* getPolygon(); 104 LDPolygon* getPolygon();
134 signals: 134 signals:
135 void codeChanged(int position, QString before, QString after); 135 void codeChanged(int position, QString before, QString after);
136 136
137 protected: 137 protected:
138 friend class Model; 138 friend class Model;
139 LDObject (Model* model = nullptr);
139 virtual ~LDObject(); 140 virtual ~LDObject();
140 141
141 private: 142 private:
142 bool m_isHidden; 143 bool m_isHidden;
143 bool m_isSelected; 144 bool m_isSelected;
160 class LDMatrixObject : public LDObject 161 class LDMatrixObject : public LDObject
161 { 162 {
162 Vertex m_position; 163 Vertex m_position;
163 164
164 public: 165 public:
165 LDMatrixObject (Model* model = nullptr);
166 LDMatrixObject (const Matrix& transformationMatrix, const Vertex& pos, Model* model = nullptr);
167
168 const Vertex& position() const; 166 const Vertex& position() const;
169 void setCoordinate (const Axis ax, double value); 167 void setCoordinate (const Axis ax, double value);
170 void setPosition (const Vertex& a); 168 void setPosition (const Vertex& a);
171 void setTransformationMatrix (const Matrix& value); 169 void setTransformationMatrix (const Matrix& value);
172 const Matrix& transformationMatrix() const; 170 const Matrix& transformationMatrix() const;
173 171
172 protected:
173 LDMatrixObject (Model* model = nullptr);
174 LDMatrixObject (const Matrix& transformationMatrix, const Vertex& pos, Model* model = nullptr);
175
174 private: 176 private:
175 Matrix m_transformationMatrix; 177 Matrix m_transformationMatrix;
176 }; 178 };
177 179
178 // 180 //
189 LDOBJ_UNCOLORED 191 LDOBJ_UNCOLORED
190 LDOBJ_SCEMANTIC 192 LDOBJ_SCEMANTIC
191 LDOBJ_NO_MATRIX 193 LDOBJ_NO_MATRIX
192 194
193 public: 195 public:
194 LDError (QString contents, QString reason, Model* model = nullptr);
195 QString reason() const; 196 QString reason() const;
196 QString contents() const; 197 QString contents() const;
197 QString fileReferenced() const; 198 QString fileReferenced() const;
198 void setFileReferenced (QString value); 199 void setFileReferenced (QString value);
199 200
201 protected:
202 LDError (QString contents, QString reason, Model* model = nullptr);
203
200 private: 204 private:
201 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that? 205 QString m_fileReferenced; // If this error was caused by inability to open a file, what file was that?
202 QString m_contents; // The LDraw code that was being parsed 206 QString m_contents; // The LDraw code that was being parsed
203 QString m_reason; 207 QString m_reason;
204 }; 208 };
229 LDOBJ_UNCOLORED 233 LDOBJ_UNCOLORED
230 LDOBJ_NON_SCEMANTIC 234 LDOBJ_NON_SCEMANTIC
231 LDOBJ_NO_MATRIX 235 LDOBJ_NO_MATRIX
232 236
233 public: 237 public:
234 LDComment (QString text, Model* model = nullptr);
235 QString text() const; 238 QString text() const;
236 void setText (QString value); 239 void setText (QString value);
240
241 protected:
242 LDComment (QString text, Model* model = nullptr);
237 243
238 private: 244 private:
239 QString m_text; 245 QString m_text;
240 }; 246 };
241 247
268 LDOBJ_UNCOLORED 274 LDOBJ_UNCOLORED
269 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } 275 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); }
270 LDOBJ_NO_MATRIX 276 LDOBJ_NO_MATRIX
271 277
272 public: 278 public:
273 LDBfc (const BfcStatement type, Model* model = nullptr);
274
275 BfcStatement statement() const; 279 BfcStatement statement() const;
276 void setStatement (BfcStatement value); 280 void setStatement (BfcStatement value);
277 QString statementToString() const; 281 QString statementToString() const;
278 282
279 static QString statementToString (BfcStatement statement); 283 static QString statementToString (BfcStatement statement);
280 284
285 protected:
286 LDBfc (const BfcStatement type, Model* model = nullptr);
287
281 private: 288 private:
282 BfcStatement m_statement; 289 BfcStatement m_statement;
283 }; 290 };
284 291
285 // 292 //
296 LDOBJ_DEFAULTCOLOR (MainColor) 303 LDOBJ_DEFAULTCOLOR (MainColor)
297 LDOBJ_SCEMANTIC 304 LDOBJ_SCEMANTIC
298 LDOBJ_HAS_MATRIX 305 LDOBJ_HAS_MATRIX
299 306
300 public: 307 public:
301 LDSubfileReference(LDDocument* reference, const Matrix& transformationMatrix, const Vertex& position, Model* model = nullptr);
302
303 // Inlines this subfile. 308 // Inlines this subfile.
304 LDDocument* fileInfo() const; 309 LDDocument* fileInfo() const;
305 virtual void getVertices (QSet<Vertex>& verts) const override; 310 virtual void getVertices (QSet<Vertex>& verts) const override;
306 void inlineContents(Model& model, bool deep, bool render); 311 void inlineContents(Model& model, bool deep, bool render);
307 QList<LDPolygon> inlinePolygons(); 312 QList<LDPolygon> inlinePolygons();
308 void setFileInfo (LDDocument* fileInfo); 313 void setFileInfo (LDDocument* fileInfo);
309 int triangleCount() const override; 314 int triangleCount() const override;
310 315
316 protected:
317 LDSubfileReference(LDDocument* reference, const Matrix& transformationMatrix, const Vertex& position, Model* model = nullptr);
318
311 private: 319 private:
312 LDDocument* m_fileInfo; 320 LDDocument* m_fileInfo;
313 }; 321 };
314 322
315 // 323 //
325 LDOBJ_COLORED 333 LDOBJ_COLORED
326 LDOBJ_DEFAULTCOLOR (EdgeColor) 334 LDOBJ_DEFAULTCOLOR (EdgeColor)
327 LDOBJ_SCEMANTIC 335 LDOBJ_SCEMANTIC
328 LDOBJ_NO_MATRIX 336 LDOBJ_NO_MATRIX
329 337
330 public: 338 protected:
331 LDLine (Vertex v1, Vertex v2, Model* model = nullptr); 339 LDLine (Vertex v1, Vertex v2, Model* model = nullptr);
332 }; 340 };
333 341
334 // 342 //
335 // LDCondLine 343 // LDCondLine
345 LDOBJ_DEFAULTCOLOR (EdgeColor) 353 LDOBJ_DEFAULTCOLOR (EdgeColor)
346 LDOBJ_SCEMANTIC 354 LDOBJ_SCEMANTIC
347 LDOBJ_NO_MATRIX 355 LDOBJ_NO_MATRIX
348 356
349 public: 357 public:
358 LDLine* becomeEdgeLine();
359
360 protected:
350 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr); 361 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr);
351 LDLine* becomeEdgeLine();
352 }; 362 };
353 363
354 // 364 //
355 // LDTriangle 365 // LDTriangle
356 // 366 //
367 LDOBJ_DEFAULTCOLOR (MainColor) 377 LDOBJ_DEFAULTCOLOR (MainColor)
368 LDOBJ_SCEMANTIC 378 LDOBJ_SCEMANTIC
369 LDOBJ_NO_MATRIX 379 LDOBJ_NO_MATRIX
370 380
371 public: 381 public:
382 int triangleCount() const override;
383
384 protected:
372 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, Model* model = nullptr); 385 LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, Model* model = nullptr);
373 int triangleCount() const override;
374 }; 386 };
375 387
376 // 388 //
377 // LDQuad 389 // LDQuad
378 // 390 //
388 LDOBJ_DEFAULTCOLOR (MainColor) 400 LDOBJ_DEFAULTCOLOR (MainColor)
389 LDOBJ_SCEMANTIC 401 LDOBJ_SCEMANTIC
390 LDOBJ_NO_MATRIX 402 LDOBJ_NO_MATRIX
391 403
392 public: 404 public:
405 int triangleCount() const override;
406
407 protected:
393 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model = nullptr); 408 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, Model* model = nullptr);
394
395 int triangleCount() const override;
396 }; 409 };
397 410
398 // 411 //
399 // LDOverlay 412 // LDOverlay
400 // 413 //
441 LDOBJ_DEFAULTCOLOR (EdgeColor) 454 LDOBJ_DEFAULTCOLOR (EdgeColor)
442 LDOBJ_SCEMANTIC 455 LDOBJ_SCEMANTIC
443 LDOBJ_NO_MATRIX 456 LDOBJ_NO_MATRIX
444 457
445 public: 458 public:
446 LDBezierCurve (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr);
447 Vertex pointAt (qreal t) const; 459 Vertex pointAt (qreal t) const;
448 void rasterize(Model& model, int segments); 460 void rasterize(Model& model, int segments);
449 QVector<LDPolygon> rasterizePolygons (int segments); 461 QVector<LDPolygon> rasterizePolygons (int segments);
462
463 protected:
464 LDBezierCurve (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model = nullptr);
450 }; 465 };
451 466
452 enum 467 enum
453 { 468 {
454 LowResolution = 16, 469 LowResolution = 16,

mercurial