86 // Base class object for all object types. Each LDObject represents a single line |
88 // Base class object for all object types. Each LDObject represents a single line |
87 // in the LDraw code file. The virtual method getType returns an enumerator |
89 // in the LDraw code file. The virtual method getType returns an enumerator |
88 // which is a token of the object's type. The object can be casted into |
90 // which is a token of the object's type. The object can be casted into |
89 // sub-classes based on this enumerator. |
91 // sub-classes based on this enumerator. |
90 // |
92 // |
91 class LDObject |
93 class LDObject : public QObject |
92 { |
94 { |
93 public: |
95 Q_OBJECT |
94 LDObject (LDDocument* document = nullptr); |
96 |
|
97 public: |
|
98 LDObject (Model* model = nullptr); |
95 |
99 |
96 virtual QString asText() const = 0; // This object as LDraw code |
100 virtual QString asText() const = 0; // This object as LDraw code |
97 LDColor color() const; |
101 LDColor color() const; |
98 LDObject* createCopy() const; |
102 LDObject* createCopy() const; |
99 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
103 virtual LDColor defaultColor() const = 0; // What color does the object default to? |
100 void deselect(); |
104 Model* model() const; |
101 void destroy(); |
|
102 LDDocument* document() const; |
|
103 LDPolygon* getPolygon(); |
105 LDPolygon* getPolygon(); |
104 virtual void getVertices (QSet<Vertex>& verts) const; |
106 virtual void getVertices (QSet<Vertex>& verts) const; |
105 virtual bool hasMatrix() const = 0; // Does this object have a matrix and position? (see LDMatrixObject) |
107 virtual bool hasMatrix() const = 0; // Does this object have a matrix and position? (see LDMatrixObject) |
106 qint32 id() const; |
108 qint32 id() const; |
107 virtual void invert() = 0; // Inverts this object (winding is reversed) |
109 virtual void invert() = 0; // Inverts this object (winding is reversed) |
108 virtual bool isColored() const = 0; |
110 virtual bool isColored() const = 0; |
109 bool isDestroyed() const; |
|
110 bool isHidden() const; |
111 bool isHidden() const; |
111 virtual bool isScemantic() const = 0; // Does this object have meaning in the part model? |
112 virtual bool isScemantic() const = 0; // Does this object have meaning in the part model? |
112 bool isSelected() const; |
113 bool isSelected() const; |
113 int lineNumber() const; |
114 int lineNumber() const; |
114 void move (Vertex vect); |
115 void move (Vertex vect); |
117 LDObject* previous() const; |
118 LDObject* previous() const; |
118 bool previousIsInvertnext (LDBfc*& ptr); |
119 bool previousIsInvertnext (LDBfc*& ptr); |
119 QColor randomColor() const; |
120 QColor randomColor() const; |
120 void replace (LDObject* other); |
121 void replace (LDObject* other); |
121 void replace (const LDObjectList& others); |
122 void replace (const LDObjectList& others); |
122 void select(); |
|
123 void setColor (LDColor color); |
123 void setColor (LDColor color); |
124 void setDocument (LDDocument* document); |
124 void setDocument (Model* model); |
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 virtual int triangleCount() const; |
128 virtual int triangleCount() const; |
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(int32 id); |
135 static LDObject* getDefault (const LDObjectType type); |
135 static LDObject* getDefault (const LDObjectType type); |
136 static QString typeName (LDObjectType type); |
136 static QString typeName (LDObjectType type); |
137 |
137 |
|
138 signals: |
|
139 void codeChanged(int position, QString before, QString after); |
|
140 |
138 protected: |
141 protected: |
|
142 friend class Model; |
139 virtual ~LDObject(); |
143 virtual ~LDObject(); |
140 |
144 |
141 private: |
145 private: |
142 bool m_isHidden; |
146 bool m_isHidden; |
143 bool m_isSelected; |
147 bool m_isSelected; |
144 bool m_isDestroyed; |
148 Model* _model; |
145 LDDocument* m_document; |
|
146 qint32 m_id; |
149 qint32 m_id; |
147 LDColor m_color; |
150 LDColor m_color; |
148 QColor m_randomColor; |
151 QColor m_randomColor; |
149 Vertex m_coords[4]; |
152 Vertex m_coords[4]; |
150 }; |
153 }; |
177 class LDMatrixObject : public LDObject |
180 class LDMatrixObject : public LDObject |
178 { |
181 { |
179 Vertex m_position; |
182 Vertex m_position; |
180 |
183 |
181 public: |
184 public: |
182 LDMatrixObject (LDDocument* document = nullptr); |
185 LDMatrixObject (Model* model = nullptr); |
183 LDMatrixObject (const Matrix& transformationMatrix, const Vertex& pos, LDDocument* document = nullptr); |
186 LDMatrixObject (const Matrix& transformationMatrix, const Vertex& pos, Model* model = nullptr); |
184 |
187 |
185 const Vertex& position() const; |
188 const Vertex& position() const; |
186 void setCoordinate (const Axis ax, double value); |
189 void setCoordinate (const Axis ax, double value); |
187 void setPosition (const Vertex& a); |
190 void setPosition (const Vertex& a); |
188 void setTransformationMatrix (const Matrix& value); |
191 void setTransformationMatrix (const Matrix& value); |
206 LDOBJ_UNCOLORED |
209 LDOBJ_UNCOLORED |
207 LDOBJ_SCEMANTIC |
210 LDOBJ_SCEMANTIC |
208 LDOBJ_NO_MATRIX |
211 LDOBJ_NO_MATRIX |
209 |
212 |
210 public: |
213 public: |
211 LDError (QString contents, QString reason, LDDocument* document = nullptr); |
214 LDError (QString contents, QString reason, Model* model = nullptr); |
212 QString reason() const; |
215 QString reason() const; |
213 QString contents() const; |
216 QString contents() const; |
214 QString fileReferenced() const; |
217 QString fileReferenced() const; |
215 void setFileReferenced (QString value); |
218 void setFileReferenced (QString value); |
216 |
219 |
285 LDOBJ_UNCOLORED |
288 LDOBJ_UNCOLORED |
286 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } |
289 LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); } |
287 LDOBJ_NO_MATRIX |
290 LDOBJ_NO_MATRIX |
288 |
291 |
289 public: |
292 public: |
290 LDBfc (const BfcStatement type, LDDocument* document = nullptr); |
293 LDBfc (const BfcStatement type, LDDocument* model = nullptr); |
291 |
294 |
292 BfcStatement statement() const; |
295 BfcStatement statement() const; |
293 void setStatement (BfcStatement value); |
296 void setStatement (BfcStatement value); |
294 QString statementToString() const; |
297 QString statementToString() const; |
295 |
298 |
313 LDOBJ_DEFAULTCOLOR (MainColor) |
316 LDOBJ_DEFAULTCOLOR (MainColor) |
314 LDOBJ_SCEMANTIC |
317 LDOBJ_SCEMANTIC |
315 LDOBJ_HAS_MATRIX |
318 LDOBJ_HAS_MATRIX |
316 |
319 |
317 public: |
320 public: |
|
321 LDSubfileReference(LDDocument* reference, const Matrix& transformationMatrix, const Vertex& position, Model* model = nullptr); |
|
322 |
318 // Inlines this subfile. |
323 // Inlines this subfile. |
319 LDDocument* fileInfo() const; |
324 LDDocument* fileInfo() const; |
320 virtual void getVertices (QSet<Vertex>& verts) const override; |
325 virtual void getVertices (QSet<Vertex>& verts) const override; |
321 LDObjectList inlineContents (bool deep, bool render); |
326 void inlineContents(Model& model, bool deep, bool render); |
322 QList<LDPolygon> inlinePolygons(); |
327 QList<LDPolygon> inlinePolygons(); |
323 void setFileInfo (LDDocument* fileInfo); |
328 void setFileInfo (LDDocument* fileInfo); |
324 int triangleCount() const override; |
329 int triangleCount() const override; |
325 |
330 |
326 private: |
331 private: |
360 LDOBJ_DEFAULTCOLOR (EdgeColor) |
365 LDOBJ_DEFAULTCOLOR (EdgeColor) |
361 LDOBJ_SCEMANTIC |
366 LDOBJ_SCEMANTIC |
362 LDOBJ_NO_MATRIX |
367 LDOBJ_NO_MATRIX |
363 |
368 |
364 public: |
369 public: |
365 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
370 LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* model = nullptr); |
366 LDLine* toEdgeLine(); |
371 LDLine* becomeEdgeLine(); |
367 }; |
372 }; |
368 |
373 |
369 // |
374 // |
370 // LDTriangle |
375 // LDTriangle |
371 // |
376 // |
403 LDOBJ_DEFAULTCOLOR (MainColor) |
408 LDOBJ_DEFAULTCOLOR (MainColor) |
404 LDOBJ_SCEMANTIC |
409 LDOBJ_SCEMANTIC |
405 LDOBJ_NO_MATRIX |
410 LDOBJ_NO_MATRIX |
406 |
411 |
407 public: |
412 public: |
408 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document = nullptr); |
413 LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* model = nullptr); |
409 |
414 |
410 // Split this quad into two triangles |
415 // Split this quad into two triangles |
411 QList<LDTriangle*> splitToTriangles(); |
416 QList<LDTriangle*> splitToTriangles(); |
412 int triangleCount() const override; |
417 int triangleCount() const override; |
413 }; |
418 }; |
459 LDOBJ_SCEMANTIC |
464 LDOBJ_SCEMANTIC |
460 LDOBJ_NO_MATRIX |
465 LDOBJ_NO_MATRIX |
461 |
466 |
462 public: |
467 public: |
463 LDBezierCurve (const Vertex& v0, const Vertex& v1, |
468 LDBezierCurve (const Vertex& v0, const Vertex& v1, |
464 const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr); |
469 const Vertex& v2, const Vertex& v3, LDDocument* model = nullptr); |
465 Vertex pointAt (qreal t) const; |
470 Vertex pointAt (qreal t) const; |
466 LDObjectList rasterize (int segments); |
471 void rasterize(Model& model, int segments); |
467 QVector<LDPolygon> rasterizePolygons (int segments); |
472 QVector<LDPolygon> rasterizePolygons (int segments); |
468 }; |
473 }; |
469 |
474 |
470 enum |
475 enum |
471 { |
476 { |