- slight refactor in ldobject methods

Mon, 05 May 2014 17:18:01 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 05 May 2014 17:18:01 +0300
changeset 767
44f0d5322628
parent 766
df2a48223e53
child 768
29e6c5552388

- slight refactor in ldobject methods

src/actionsEdit.cc file | annotate | diff | comparison | revisions
src/addObjectDialog.cc file | annotate | diff | comparison | revisions
src/basics.cc file | annotate | diff | comparison | revisions
src/glRenderer.cc file | annotate | diff | comparison | revisions
src/ldDocument.cc file | annotate | diff | comparison | revisions
src/ldObject.cc file | annotate | diff | comparison | revisions
src/ldObject.h file | annotate | diff | comparison | revisions
src/mainWindow.cc file | annotate | diff | comparison | revisions
--- a/src/actionsEdit.cc	Mon May 05 17:09:25 2014 +0300
+++ b/src/actionsEdit.cc	Mon May 05 17:18:01 2014 +0300
@@ -306,12 +306,12 @@
 
 	for (LDObject* obj : selection())
 	{
-		if (obj->vertices() < 2)
+		if (obj->numVertices() < 2)
 			continue;
 
 		int ln = obj->lineNumber();
 
-		for (int i = 0; i < obj->vertices(); ++i)
+		for (int i = 0; i < obj->numVertices(); ++i)
 		{
 			LDVertex* vert = new LDVertex;
 			vert->pos = obj->vertex (i);
@@ -454,9 +454,9 @@
 	// Apply the above matrix to everything
 	for (LDObject* obj : sel)
 	{
-		if (obj->vertices())
+		if (obj->numVertices())
 		{
-			for (int i = 0; i < obj->vertices(); ++i)
+			for (int i = 0; i < obj->numVertices(); ++i)
 			{
 				Vertex v = obj->vertex (i);
 				rotateVertex (v, rotpoint, transform);
@@ -545,7 +545,7 @@
 		}
 		else
 		{
-			for (int i = 0; i < obj->vertices(); ++i)
+			for (int i = 0; i < obj->numVertices(); ++i)
 			{
 				Vertex v = obj->vertex (i);
 				v.apply ([](Axis, double& a) { roundToDecimals (a, 3); });
@@ -609,7 +609,7 @@
 
 	for (LDObject* obj : selection())
 	{
-		for (int i = 0; i < obj->vertices(); ++i)
+		for (int i = 0; i < obj->numVertices(); ++i)
 		{
 			Vertex v = obj->vertex (i);
 
@@ -655,7 +655,7 @@
 
 	for (LDObject* obj : selection())
 	{
-		for (int i = 0; i < obj->vertices(); ++i)
+		for (int i = 0; i < obj->numVertices(); ++i)
 		{
 			Vertex v = obj->vertex (i);
 
--- a/src/addObjectDialog.cc	Mon May 05 17:09:25 2014 +0300
+++ b/src/addObjectDialog.cc	Mon May 05 17:18:01 2014 +0300
@@ -380,7 +380,7 @@
 			if (not obj)
 				obj = LDObject::getDefault (type);
 
-			for (int i = 0; i < obj->vertices(); ++i)
+			for (int i = 0; i < obj->numVertices(); ++i)
 			{
 				Vertex v;
 
--- a/src/basics.cc	Mon May 05 17:09:25 2014 +0300
+++ b/src/basics.cc	Mon May 05 17:18:01 2014 +0300
@@ -240,7 +240,7 @@
 		case LDObject::EQuad:
 		case LDObject::ECondLine:
 		{
-			for (int i = 0; i < obj->vertices(); ++i)
+			for (int i = 0; i < obj->numVertices(); ++i)
 				calcVertex (obj->vertex (i));
 		} break;
 
--- a/src/glRenderer.cc	Mon May 05 17:09:25 2014 +0300
+++ b/src/glRenderer.cc	Mon May 05 17:18:01 2014 +0300
@@ -1303,7 +1303,7 @@
 		{
 			if (obj->isSelected())
 			{
-				obj->unselect();
+				obj->deselect();
 				removedObj = obj;
 				break;
 			}
@@ -1447,7 +1447,7 @@
 				// Copy the vertices from m_rectverts
 				updateRectVerts();
 
-				for (int i = 0; i < quad->vertices(); ++i)
+				for (int i = 0; i < quad->numVertices(); ++i)
 					quad->setVertex (i, m_rectverts[i]);
 
 				quad->setColor (maincolor);
@@ -1483,7 +1483,7 @@
 
 						obj->setColor (maincolor);
 
-						for (int i = 0; i < obj->vertices(); ++i)
+						for (int i = 0; i < obj->numVertices(); ++i)
 							obj->setVertex (i, verts[i]);
 
 						objs << obj;
@@ -1653,9 +1653,9 @@
 {
 	QList<Vertex> verts;
 
-	if (obj->vertices() >= 2)
+	if (obj->numVertices() >= 2)
 	{
-		for (int i = 0; i < obj->vertices(); ++i)
+		for (int i = 0; i < obj->numVertices(); ++i)
 			verts << obj->vertex (i);
 	}
 	elif (obj->type() == LDObject::ESubfile)
--- a/src/ldDocument.cc	Mon May 05 17:09:25 2014 +0300
+++ b/src/ldDocument.cc	Mon May 05 17:18:01 2014 +0300
@@ -1113,7 +1113,7 @@
 	}
 	else
 	{
-		for (int i = 0; i < obj->vertices(); ++i)
+		for (int i = 0; i < obj->numVertices(); ++i)
 			addKnownVertexReference (obj->vertex (i));
 	}
 }
@@ -1137,7 +1137,7 @@
 	}
 	else
 	{
-		for (int i = 0; i < obj->vertices(); ++i)
+		for (int i = 0; i < obj->numVertices(); ++i)
 			removeKnownVertexReference (obj->vertex (i));
 	}
 }
@@ -1147,7 +1147,7 @@
 void LDDocument::forgetObject (LDObject* obj)
 {
 	int idx = obj->lineNumber();
-	obj->unselect();
+	obj->deselect();
 	assert (m_objects[idx] == obj);
 
 	if (not isImplicit() && not (flags() & DOCF_IsBeingDestroyed))
@@ -1224,7 +1224,7 @@
 	}
 
 	removeKnownVerticesOf (m_objects[idx]);
-	m_objects[idx]->unselect();
+	m_objects[idx]->deselect();
 	m_objects[idx]->setDocument (null);
 	obj->setDocument (this);
 	addKnownVerticesOf (obj);
@@ -1305,7 +1305,7 @@
 			delete data;
 		}
 
-		for (int i = 0; i < obj->vertices(); ++i)
+		for (int i = 0; i < obj->numVertices(); ++i)
 			m_storedVertices << obj->vertex (i);
 
 		obj->destroy();
--- a/src/ldObject.cc	Mon May 05 17:09:25 2014 +0300
+++ b/src/ldObject.cc	Mon May 05 17:18:01 2014 +0300
@@ -264,7 +264,7 @@
 {
 	// If this object was selected, unselect it now
 	if (isSelected())
-		unselect();
+		deselect();
 
 	// If this object was associated to a file, remove it off it now
 	if (document())
@@ -295,7 +295,7 @@
 		case LDObject::ETriangle:
 		case LDObject::EQuad:
 
-			for (int i = 0; i < obj->vertices(); ++i)
+			for (int i = 0; i < obj->numVertices(); ++i)
 			{
 				Vertex v = obj->vertex (i);
 				v.transform (transform, pos);
@@ -538,7 +538,7 @@
 	}
 	else
 	{
-		for (int i = 0; i < vertices(); ++i)
+		for (int i = 0; i < numVertices(); ++i)
 			setVertex (i, vertex (i) + vect);
 	}
 }
@@ -657,7 +657,7 @@
 {
 	LDLine* repl = new LDLine;
 
-	for (int i = 0; i < repl->vertices(); ++i)
+	for (int i = 0; i < repl->numVertices(); ++i)
 		repl->setVertex (i, vertex (i));
 
 	repl->setColor (color());
@@ -814,7 +814,7 @@
 
 // =============================================================================
 //
-void LDObject::unselect()
+void LDObject::deselect()
 {
 	assert (document() != null);
 	document()->removeFromSelection (this);
--- a/src/ldObject.h	Mon May 05 17:09:25 2014 +0300
+++ b/src/ldObject.h	Mon May 05 17:18:01 2014 +0300
@@ -34,11 +34,11 @@
 	{													\
 		return LDObject::E##T;							\
 	}													\
-	virtual String asText() const override;		\
+	virtual String asText() const override;				\
 	virtual void invert() override;
 
 #define LDOBJ_NAME(N)          virtual String typeName() const override { return #N; }
-#define LDOBJ_VERTICES(V)      virtual int vertices() const override { return V; }
+#define LDOBJ_VERTICES(V)      virtual int numVertices() const override { return V; }
 #define LDOBJ_SETCOLORED(V)    virtual bool isColored() const override { return V; }
 #define LDOBJ_COLORED          LDOBJ_SETCOLORED (true)
 #define LDOBJ_UNCOLORED        LDOBJ_SETCOLORED (false)
@@ -97,23 +97,17 @@
 
 		LDObject();
 
+		// This object as LDraw code
+		virtual String				asText() const = 0;
+
 		// Makes a copy of this object
 		LDObject*					createCopy() const;
 
 		// Deletes this object
 		void						destroy();
 
-		// Index (i.e. line number) of this object
-		long						lineNumber() const;
-
-		// Type enumerator of this object
-		virtual Type				type() const = 0;
-
-		// Get a vertex by index
-		const Vertex&				vertex (int i) const;
-
-		// Type name of this object
-		virtual String				typeName() const = 0;
+		// Removes this object from selection
+		void						deselect();
 
 		// Does this object have a matrix and position? (see LDMatrixObject)
 		virtual bool				hasMatrix() const = 0;
@@ -127,18 +121,21 @@
 		// Does this object have meaning in the part model?
 		virtual bool				isScemantic() const = 0;
 
+		// Index (i.e. line number) of this object
+		long						lineNumber() const;
+
 		// Moves this object using the given vertex as a movement List
 		void						move (Vertex vect);
 
 		// Object after this in the current file
 		LDObject*					next() const;
 
+		// Number of vertices this object has
+		virtual int					numVertices() const = 0;
+
 		// Object prior to this in the current file
 		LDObject*					previous() const;
 
-		// This object as LDraw code
-		virtual String				asText() const = 0;
-
 		// Replace this LDObject with another LDObject. Object is deleted in the process.
 		void						replace (LDObject* other);
 
@@ -157,11 +154,14 @@
 		// What object in the current file ultimately references this?
 		LDObject*					topLevelParent();
 
-		// Removes this object from selection // TODO: rename to deselect?
-		void						unselect();
+		// Type enumerator of this object
+		virtual Type				type() const = 0;
 
-		// Number of vertices this object has // TODO: rename to getNumVertices
-		virtual int					vertices() const = 0;
+		// Type name of this object
+		virtual String				typeName() const = 0;
+
+		// Get a vertex by index
+		const Vertex&				vertex (int i) const;
 
 		// Get type name by enumerator
 		static String typeName (LDObject::Type type);
--- a/src/mainWindow.cc	Mon May 05 17:09:25 2014 +0300
+++ b/src/mainWindow.cc	Mon May 05 17:18:01 2014 +0300
@@ -343,7 +343,7 @@
 			case LDObject::EQuad:
 			case LDObject::ECondLine:
 			{
-				for (int i = 0; i < obj->vertices(); ++i)
+				for (int i = 0; i < obj->numVertices(); ++i)
 				{
 					if (i != 0)
 						descr += ", ";

mercurial