src/ldObject.h

changeset 996
9ecc878c7dea
parent 995
7986584e7498
--- a/src/ldObject.h	Sun Sep 06 20:45:51 2015 +0300
+++ b/src/ldObject.h	Tue Sep 22 00:59:21 2015 +0300
@@ -37,7 +37,6 @@
 	virtual void invert() override;								\
 
 #define LDOBJ_NAME(N)          public: virtual QString typeName() const override { return #N; }
-#define LDOBJ_VERTICES(V)      public: virtual int numVertices() const override { return V; }
 #define LDOBJ_SETCOLORED(V)    public: virtual bool isColored() const override { return V; }
 #define LDOBJ_COLORED          LDOBJ_SETCOLORED (true)
 #define LDOBJ_UNCOLORED        LDOBJ_SETCOLORED (false) LDOBJ_DEFAULTCOLOR (MainColor)
@@ -54,7 +53,6 @@
 class QListWidgetItem;
 class LDSubfile;
 class LDDocument;
-
 class LDBfc;
 
 //
@@ -99,9 +97,9 @@
 	void deselect(); 
 	void destroy();
 	LDDocument* document() const;
-	LDPolygon* getPolygon();
 	virtual void getVertices (QVector<Vertex>& verts) const;
-	virtual bool hasMatrix() const = 0; // Does this object have a matrix and position? (see LDMatrixObject)
+	virtual bool hasMatrix() const { return false; }
+	virtual bool hasVertices() const { return false; }
 	qint32 id() const;
 	virtual void invert() = 0; // Inverts this object (winding is reversed)
 	virtual bool isColored() const = 0;
@@ -112,7 +110,6 @@
 	int lineNumber() const;
 	void move (Vertex vect);
 	LDObject* next() const;
-	virtual int numVertices() const = 0;
 	LDObject* previous() const;
 	bool previousIsInvertnext (LDBfc*& ptr);
 	QColor randomColor() const;
@@ -121,12 +118,10 @@
 	void setColor (LDColor color);
 	void setDocument (LDDocument* document);
 	void setHidden (bool value);
-	void setVertex (int i, const Vertex& vert);
 	void swap (LDObject* other);
-	LDObject* topLevelParent();
+	virtual void transform (const Matrix& transformationMatrix, const Vertex& position);
 	virtual LDObjectType type() const = 0;
 	virtual QString typeName() const = 0;
-	const Vertex& vertex (int i) const;
 
 	static QString describeObjects (const LDObjectList& objs);
 	static LDObject* fromID (int id);
@@ -141,12 +136,10 @@
 	bool m_isHidden;
 	bool m_isSelected;
 	bool m_isDestroyed;
-	LDObject* m_parent;
 	LDDocument* m_document;
 	qint32 m_id;
 	LDColor m_color;
 	QColor m_randomColor;
-	Vertex m_coords[4];
 };
 
 template<typename T, typename... Args>
@@ -176,20 +169,39 @@
 //
 class LDMatrixObject : public LDObject
 {
-	Vertex m_position;
-
 public:
 	LDMatrixObject (LDDocument* document = nullptr);
-	LDMatrixObject (const Matrix& transform, const Vertex& pos, LDDocument* document = nullptr);
+	LDMatrixObject (const Matrix& transformationMatrix, const Vertex& position, LDDocument* document = nullptr);
 
+	virtual bool hasMatrix() const { return true; }
 	const Vertex& position() const;
 	void setCoordinate (const Axis ax, double value);
 	void setPosition (const Vertex& a);
-	const Matrix& transform() const;
-	void setTransform (const Matrix& value);
+	void setTransformationMatrix (const Matrix& value);
+	virtual void transform (const Matrix& transformationMatrix, const Vertex& position);
+	const Matrix& transformationMatrix() const;
 
 private:
-	Matrix m_transform;
+	Vertex m_position;
+	Matrix m_transformationMatrix;
+};
+
+class LDVertexObject : public LDObject
+{
+public:
+	LDVertexObject (LDDocument* document = nullptr);
+
+	LDPolygon* getPolygon();
+	virtual void getVertices (QVector<Vertex>& verts) const;
+	virtual bool hasVertices() const { return true; }
+	virtual int numVertices() const = 0;
+	void setVertex (int i, const Vertex& vert);
+	virtual void transform (const Matrix& transformationMatrix, const Vertex& position);
+	const Vertex& vertex (int i) const;
+	QSet<Vertex> vertexSet() const;
+
+private:
+	Vertex m_coordinates[4];
 };
 
 //
@@ -202,16 +214,14 @@
 {
 	LDOBJ (Error)
 	LDOBJ_NAME (error)
-	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
 	LDOBJ_SCEMANTIC
-	LDOBJ_NO_MATRIX
-
 public:
 	LDError (QString contents, QString reason, LDDocument* document = nullptr);
-	QString reason() const;
+
 	QString contents() const;
 	QString fileReferenced() const;
+	QString reason() const;
 	void setFileReferenced (QString value);
 
 private:
@@ -228,10 +238,8 @@
 {
 	LDOBJ (Empty)
 	LDOBJ_NAME (empty)
-	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
 	LDOBJ_NON_SCEMANTIC
-	LDOBJ_NO_MATRIX
 };
 
 //
@@ -242,10 +250,8 @@
 {
 	LDOBJ (Comment)
 	LDOBJ_NAME (comment)
-	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
 	LDOBJ_NON_SCEMANTIC
-	LDOBJ_NO_MATRIX
 
 public:
 	LDComment (QString text, LDDocument* document = nullptr);
@@ -282,16 +288,14 @@
 public:
 	LDOBJ (Bfc)
 	LDOBJ_NAME (bfc)
-	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
 	LDOBJ_CUSTOM_SCEMANTIC { return (statement() == BfcStatement::InvertNext); }
-	LDOBJ_NO_MATRIX
 
 public:
 	LDBfc (const BfcStatement type, LDDocument* document = nullptr);
 
+	void setStatement (BfcStatement value);
 	BfcStatement statement() const;
-	void setStatement (BfcStatement value);
 	QString statementToString() const;
 
 	static QString statementToString (BfcStatement statement);
@@ -309,11 +313,9 @@
 {
 	LDOBJ (Subfile)
 	LDOBJ_NAME (subfile)
-	LDOBJ_VERTICES (0)
 	LDOBJ_COLORED
 	LDOBJ_DEFAULTCOLOR (MainColor)
 	LDOBJ_SCEMANTIC
-	LDOBJ_HAS_MATRIX
 
 public:
 	// Inlines this subfile.
@@ -332,18 +334,17 @@
 //
 // Represents a single code-2 line in the LDraw code file.
 //
-class LDLine : public LDObject
+class LDLine : public LDVertexObject
 {
 	LDOBJ (Line)
 	LDOBJ_NAME (line)
-	LDOBJ_VERTICES (2)
 	LDOBJ_COLORED
 	LDOBJ_DEFAULTCOLOR (EdgeColor)
 	LDOBJ_SCEMANTIC
-	LDOBJ_NO_MATRIX
 
 public:
 	LDLine (Vertex v1, Vertex v2, LDDocument* document = nullptr);
+	int numVertices() const override { return 2; }
 };
 
 //
@@ -355,15 +356,14 @@
 {
 	LDOBJ (CondLine)
 	LDOBJ_NAME (condline)
-	LDOBJ_VERTICES (4)
 	LDOBJ_COLORED
 	LDOBJ_DEFAULTCOLOR (EdgeColor)
 	LDOBJ_SCEMANTIC
-	LDOBJ_NO_MATRIX
 
 public:
 	LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr);
 	LDLine* toEdgeLine();
+	int numVertices() const override { return 4; }
 };
 
 //
@@ -373,18 +373,17 @@
 // and v2 contain the end-points of this triangle. dColor is the color the
 // triangle is colored with.
 //
-class LDTriangle : public LDObject
+class LDTriangle : public LDVertexObject
 {
 	LDOBJ (Triangle)
 	LDOBJ_NAME (triangle)
-	LDOBJ_VERTICES (3)
 	LDOBJ_COLORED
 	LDOBJ_DEFAULTCOLOR (MainColor)
 	LDOBJ_SCEMANTIC
-	LDOBJ_NO_MATRIX
 
 public:
 	LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr);
+	int numVertices() const override { return 3; }
 };
 
 //
@@ -393,21 +392,20 @@
 // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points
 // of the quad, dColor is the color used for the quad.
 //
-class LDQuad : public LDObject
+class LDQuad : public LDVertexObject
 {
 	LDOBJ (Quad)
 	LDOBJ_NAME (quad)
-	LDOBJ_VERTICES (4)
 	LDOBJ_COLORED
 	LDOBJ_DEFAULTCOLOR (MainColor)
 	LDOBJ_SCEMANTIC
-	LDOBJ_NO_MATRIX
 
 public:
 	LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document = nullptr);
 
 	// Split this quad into two triangles
 	QList<LDTriangle*> splitToTriangles();
+	int numVertices() const override { return 4; }
 };
 
 //
@@ -419,10 +417,8 @@
 {
 	LDOBJ (Overlay)
 	LDOBJ_NAME (overlay)
-	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
 	LDOBJ_NON_SCEMANTIC
-	LDOBJ_NO_MATRIX
 
 public:
 	int camera() const;

mercurial