src/ldtypes.cc

changeset 604
01bdac75994a
parent 603
47e7773c7841
child 606
3dd6f343ec06
--- a/src/ldtypes.cc	Tue Jan 07 08:53:27 2014 +0200
+++ b/src/ldtypes.cc	Tue Jan 07 11:56:26 2014 +0200
@@ -1,11 +1,11 @@
 /*
  *  LDForge: LDraw parts authoring CAD
- *  Copyright( C) 2013, 2014 Santeri Piippo
+ *  Copyright (C) 2013, 2014 Santeri Piippo
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation, either version 3 of the License, or
- * ( at your option) any later version.
+ *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -25,9 +25,9 @@
 #include "gldraw.h"
 #include "colors.h"
 
-cfg( String, ld_defaultname, "");
-cfg( String, ld_defaultuser, "");
-cfg( Int, ld_defaultlicense, 0);
+cfg (String, ld_defaultname, "");
+cfg (String, ld_defaultuser, "");
+cfg (Int, ld_defaultlicense, 0);
 
 // List of all LDObjects
 static QList<LDObject*> g_LDObjects;
@@ -36,14 +36,14 @@
 // LDObject constructors
 // -----------------------------------------------------------------------------
 LDObject::LDObject() :
-	m_Hidden( false),
-	m_Selected( false),
-	m_Parent( null),
-	m_File( null),
-	m_GLInit( false),
-	qObjListEntry( null)
+	m_Hidden (false),
+	m_Selected (false),
+	m_Parent (null),
+	m_File (null),
+	m_GLInit (false),
+	qObjListEntry (null)
 {
-	memset( m_coords, 0, sizeof m_coords);
+	memset (m_coords, 0, sizeof m_coords);
 	chooseID();
 	g_LDObjects << this;
 }
@@ -54,15 +54,15 @@
 {
 	int32 id = 1; // 0 shalt be null
 
-	for( LDObject* obj : g_LDObjects)
+	for (LDObject* obj : g_LDObjects)
 	{
-		assert( obj != this);
+		assert (obj != this);
 
-		if( obj->getID() >= id)
+		if (obj->getID() >= id)
 			id = obj->getID() + 1;
 	}
 
-	setID( id);
+	setID (id);
 }
 
 // =============================================================================
@@ -72,7 +72,7 @@
 // -----------------------------------------------------------------------------
 LDObject::Type LDObject::getType() const
 {
-	return LDObject::Unidentified;
+	return LDObject::EUnidentified;
 }
 
 bool LDObject::hasMatrix() const
@@ -102,11 +102,11 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDObject::setVertexCoord( int i, Axis ax, double value)
+void LDObject::setVertexCoord (int i, Axis ax, double value)
 {
-	vertex v = getVertex( i);
+	Vertex v = getVertex (i);
 	v[ax] = value;
-	setVertex( i, v);
+	setVertex (i, v);
 }
 
 LDError::LDError() {}
@@ -115,14 +115,14 @@
 // -----------------------------------------------------------------------------
 str LDComment::raw() const
 {
-	return fmt( "0 %1", text);
+	return fmt ("0 %1", text);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
 str LDSubfile::raw() const
 {
-	str val = fmt( "1 %1 %2 ", getColor(), getPosition());
+	str val = fmt ("1 %1 %2 ", getColor(), getPosition());
 	val += getTransform().stringRep();
 	val += ' ';
 	val += getFileInfo()->getName();
@@ -133,10 +133,10 @@
 // -----------------------------------------------------------------------------
 str LDLine::raw() const
 {
-	str val = fmt( "2 %1", getColor());
+	str val = fmt ("2 %1", getColor());
 
-	for( int i = 0; i < 2; ++i)
-		val += fmt( " %1", getVertex( i));
+	for (int i = 0; i < 2; ++i)
+		val += fmt (" %1", getVertex (i));
 
 	return val;
 }
@@ -145,10 +145,10 @@
 // -----------------------------------------------------------------------------
 str LDTriangle::raw() const
 {
-	str val = fmt( "3 %1", getColor());
+	str val = fmt ("3 %1", getColor());
 
-	for( int i = 0; i < 3; ++i)
-		val += fmt( " %1", getVertex( i));
+	for (int i = 0; i < 3; ++i)
+		val += fmt (" %1", getVertex (i));
 
 	return val;
 }
@@ -157,10 +157,10 @@
 // -----------------------------------------------------------------------------
 str LDQuad::raw() const
 {
-	str val = fmt( "4 %1", getColor());
+	str val = fmt ("4 %1", getColor());
 
-	for( int i = 0; i < 4; ++i)
-		val += fmt( " %1", getVertex( i));
+	for (int i = 0; i < 4; ++i)
+		val += fmt (" %1", getVertex (i));
 
 	return val;
 }
@@ -169,11 +169,11 @@
 // -----------------------------------------------------------------------------
 str LDCondLine::raw() const
 {
-	str val = fmt( "5 %1", getColor());
+	str val = fmt ("5 %1", getColor());
 
 	// Add the coordinates
-	for( int i = 0; i < 4; ++i)
-		val += fmt( " %1", getVertex( i));
+	for (int i = 0; i < 4; ++i)
+		val += fmt (" %1", getVertex (i));
 
 	return val;
 }
@@ -189,7 +189,7 @@
 // -----------------------------------------------------------------------------
 str LDVertex::raw() const
 {
-	return fmt( "0 !LDFORGE VERTEX %1 %2", getColor(), pos);
+	return fmt ("0 !LDFORGE VERTEX %1 %2", getColor(), pos);
 }
 
 // =============================================================================
@@ -217,7 +217,7 @@
 
 str LDBFC::raw() const
 {
-	return fmt( "0 BFC %1", LDBFC::statements[type]);
+	return fmt ("0 BFC %1", LDBFC::statements[type]);
 }
 
 // =============================================================================
@@ -230,12 +230,12 @@
 	// |   |  ==>  | /    / |
 	// |   |       |/    /  |
 	// 1---2       1    1---2
-	LDTriangle* tri1 = new LDTriangle( getVertex( 0), getVertex( 1), getVertex( 3));
-	LDTriangle* tri2 = new LDTriangle( getVertex( 1), getVertex( 2), getVertex( 3));
+	LDTriangle* tri1 = new LDTriangle (getVertex (0), getVertex (1), getVertex (3));
+	LDTriangle* tri2 = new LDTriangle (getVertex (1), getVertex (2), getVertex (3));
 
 	// The triangles also inherit the quad's color
-	tri1->setColor( getColor());
-	tri2->setColor( getColor());
+	tri1->setColor (getColor());
+	tri2->setColor (getColor());
 
 	QList<LDTriangle*> triangles;
 	triangles << tri1;
@@ -245,13 +245,13 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDObject::replace( LDObject* other)
+void LDObject::replace (LDObject* other)
 {
 	long idx = getIndex();
-	assert( idx != -1);
+	assert (idx != -1);
 
 	// Replace the instance of the old object with the new object
-	getFile()->setObject( idx, other);
+	getFile()->setObject (idx, other);
 
 	// Remove the old object
 	deleteSelf();
@@ -259,28 +259,28 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDObject::swap( LDObject* other)
+void LDObject::swap (LDObject* other)
 {
-	assert( getFile() == other->getFile());
-	getFile()->swapObjects( this, other);
+	assert (getFile() == other->getFile());
+	getFile()->swapObjects (this, other);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-LDLine::LDLine( vertex v1, vertex v2)
+LDLine::LDLine (Vertex v1, Vertex v2)
 {
-	setVertex( 0, v1);
-	setVertex( 1, v2);
+	setVertex (0, v1);
+	setVertex (1, v2);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-LDQuad::LDQuad( const vertex& v0, const vertex& v1, const vertex& v2, const vertex& v3)
+LDQuad::LDQuad (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3)
 {
-	setVertex( 0, v0);
-	setVertex( 1, v1);
-	setVertex( 2, v2);
-	setVertex( 3, v3);
+	setVertex (0, v0);
+	setVertex (1, v1);
+	setVertex (2, v2);
+	setVertex (3, v3);
 }
 
 // =============================================================================
@@ -296,51 +296,51 @@
 void LDObject::deleteSelf()
 {
 	// If this object was selected, unselect it now
-	if( isSelected())
+	if (isSelected())
 		unselect();
 
 	// If this object was associated to a file, remove it off it now
-	if( getFile())
-		getFile()->forgetObject( this);
+	if (getFile())
+		getFile()->forgetObject (this);
 
 	// Delete the GL lists
-	GL::deleteLists( this);
+	GL::deleteLists (this);
 
 	// Remove this object from the list of LDObjects
-	g_LDObjects.removeOne( this);
+	g_LDObjects.removeOne (this);
 
 	delete this;
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-static void transformObject( LDObject* obj, matrix transform, vertex pos, int parentcolor)
+static void transformObject (LDObject* obj, Matrix transform, Vertex pos, int parentcolor)
 {
-	switch( obj->getType())
+	switch (obj->getType())
 	{
-		case LDObject::Line:
-		case LDObject::CondLine:
-		case LDObject::Triangle:
-		case LDObject::Quad:
+		case LDObject::ELine:
+		case LDObject::ECondLine:
+		case LDObject::ETriangle:
+		case LDObject::EQuad:
 
-			for( int i = 0; i < obj->vertices(); ++i)
+			for (int i = 0; i < obj->vertices(); ++i)
 			{
-				vertex v = obj->getVertex( i);
-				v.transform( transform, pos);
-				obj->setVertex( i, v);
+				Vertex v = obj->getVertex (i);
+				v.transform (transform, pos);
+				obj->setVertex (i, v);
 			}
 
 			break;
 
-		case LDObject::Subfile:
+		case LDObject::ESubfile:
 		{
-			LDSubfile* ref = static_cast<LDSubfile*>( obj);
-			matrix newMatrix = transform * ref->getTransform();
-			vertex newpos = ref->getPosition();
+			LDSubfile* ref = static_cast<LDSubfile*> (obj);
+			Matrix newMatrix = transform * ref->getTransform();
+			Vertex newpos = ref->getPosition();
 
-			newpos.transform( transform, pos);
-			ref->setPosition( newpos);
-			ref->setTransform( newMatrix);
+			newpos.transform (transform, pos);
+			ref->setPosition (newpos);
+			ref->setTransform (newMatrix);
 		}
 		break;
 
@@ -348,22 +348,22 @@
 			break;
 	}
 
-	if( obj->getColor() == maincolor)
-		obj->setColor( parentcolor);
+	if (obj->getColor() == maincolor)
+		obj->setColor (parentcolor);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-QList<LDObject*> LDSubfile::inlineContents( InlineFlags flags)
+QList<LDObject*> LDSubfile::inlineContents (InlineFlags flags)
 {
-	QList<LDObject*> objs = getFileInfo()->inlineContents( flags);
+	QList<LDObject*> objs = getFileInfo()->inlineContents (flags);
 
 	// Transform the objects
-	for( LDObject* obj : objs)
+	for (LDObject* obj : objs)
 	{
 		// Set the parent now so we know what inlined the object.
-		obj->setParent( this);
-		transformObject( obj, getTransform(), getPosition(), getColor());
+		obj->setParent (this);
+		transformObject (obj, getTransform(), getPosition(), getColor());
 	}
 
 	return objs;
@@ -373,10 +373,10 @@
 // -----------------------------------------------------------------------------
 long LDObject::getIndex() const
 {
-	assert( getFile() != null);
+	assert (getFile() != null);
 
-	for( int i = 0; i < getFile()->getObjectCount(); ++i)
-		if( getFile()->getObject( i) == this)
+	for (int i = 0; i < getFile()->getObjectCount(); ++i)
+		if (getFile()->getObject (i) == this)
 			return i;
 
 	return -1;
@@ -384,53 +384,53 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDObject::moveObjects( QList<LDObject*> objs, const bool up)
+void LDObject::moveObjects (QList<LDObject*> objs, const bool up)
 {
-	if( objs.isEmpty())
+	if (objs.isEmpty())
 		return;
 
 	// If we move down, we need to iterate the array in reverse order.
-	const long start = up ? 0 :( objs.size() - 1);
+	const long start = up ? 0 : (objs.size() - 1);
 	const long end = up ? objs.size() : -1;
 	const long incr = up ? 1 : -1;
 	QList<LDObject*> objsToCompile;
 	LDDocument* file = objs[0]->getFile();
 
-	for( long i = start; i != end; i += incr)
+	for (long i = start; i != end; i += incr)
 	{
 		LDObject* obj = objs[i];
 
 		const long idx = obj->getIndex(),
-				   target = idx +( up ? -1 : 1);
+				   target = idx + (up ? -1 : 1);
 
-		if( ( up && idx == 0) ||( !up && idx ==( long)( file->getObjects().size() - 1)))
+		if ( (up && idx == 0) || (!up && idx == (long) (file->getObjects().size() - 1)))
 		{
 			// One of the objects hit the extrema. If this happens, this should be the first
 			// object to be iterated on. Thus, nothing has changed yet and it's safe to just
 			// abort the entire operation.
-			assert( i == start);
+			assert (i == start);
 			return;
 		}
 
 		objsToCompile << obj;
-		objsToCompile << file->getObject( target);
+		objsToCompile << file->getObject (target);
 
-		obj->swap( file->getObject( target));
+		obj->swap (file->getObject (target));
 	}
 
-	removeDuplicates( objsToCompile);
+	removeDuplicates (objsToCompile);
 
 	// The objects need to be recompiled, otherwise their pick lists are left with
 	// the wrong index colors which messes up selection.
-	for( LDObject* obj : objsToCompile)
-		g_win->R()->compileObject( obj);
+	for (LDObject* obj : objsToCompile)
+		g_win->R()->compileObject (obj);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-str LDObject::typeName( LDObject::Type type)
+str LDObject::typeName (LDObject::Type type)
 {
-	LDObject* obj = LDObject::getDefault( type);
+	LDObject* obj = LDObject::getDefault (type);
 	str name = obj->getTypeName();
 	obj->deleteSelf();
 	return name;
@@ -438,36 +438,36 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-str LDObject::describeObjects( const QList<LDObject*>& objs)
+str LDObject::describeObjects (const QList<LDObject*>& objs)
 {
 	bool firstDetails = true;
 	str text = "";
 
-	if( objs.isEmpty())
+	if (objs.isEmpty())
 		return "nothing"; // :)
 
-	for( long i = 0; i < LDObject::NumTypes; ++i)
+	for (long i = 0; i < ENumTypes; ++i)
 	{
-		LDObject::Type objType =( LDObject::Type) i;
+		Type objType = (Type) i;
 		int count = 0;
 
-		for( LDObject * obj : objs)
-			if( obj->getType() == objType)
+		for (LDObject * obj : objs)
+			if (obj->getType() == objType)
 				count++;
 
-		if( count == 0)
+		if (count == 0)
 			continue;
 
-		if( !firstDetails)
+		if (!firstDetails)
 			text += ", ";
 
-		str noun = fmt( "%1%2", typeName( objType), plural( count));
+		str noun = fmt ("%1%2", typeName (objType), plural (count));
 
 		// Plural of "vertex" is "vertices", correct that
-		if( objType == LDObject::Vertex && count != 1)
+		if (objType == EVertex && count != 1)
 			noun = "vertices";
 
-		text += fmt( "%1 %2", count, noun);
+		text += fmt ("%1 %2", count, noun);
 		firstDetails = false;
 	}
 
@@ -478,12 +478,12 @@
 // -----------------------------------------------------------------------------
 LDObject* LDObject::topLevelParent()
 {
-	if( !getParent())
+	if (!getParent())
 		return this;
 
 	LDObject* it = this;
 
-	while( it->getParent())
+	while (it->getParent())
 		it = it->getParent();
 
 	return it;
@@ -494,12 +494,12 @@
 LDObject* LDObject::next() const
 {
 	long idx = getIndex();
-	assert( idx != -1);
+	assert (idx != -1);
 
-	if( idx ==( long) getFile()->getObjectCount() - 1)
+	if (idx == (long) getFile()->getObjectCount() - 1)
 		return null;
 
-	return getFile()->getObject( idx + 1);
+	return getFile()->getObject (idx + 1);
 }
 
 // =============================================================================
@@ -507,55 +507,55 @@
 LDObject* LDObject::prev() const
 {
 	long idx = getIndex();
-	assert( idx != -1);
+	assert (idx != -1);
 
-	if( idx == 0)
+	if (idx == 0)
 		return null;
 
-	return getFile()->getObject( idx - 1);
+	return getFile()->getObject (idx - 1);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDObject::move( vertex vect)
+void LDObject::move (Vertex vect)
 {
-	if( hasMatrix())
+	if (hasMatrix())
 	{
-		LDMatrixObject* mo = dynamic_cast<LDMatrixObject*>( this);
-		mo->setPosition( mo->getPosition() + vect);
+		LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (this);
+		mo->setPosition (mo->getPosition() + vect);
 	}
-	elif( getType() == LDObject::Vertex)
+	elif (getType() == LDObject::EVertex)
 	{
 		// ugh
-		static_cast<LDVertex*>( this)->pos += vect;
+		static_cast<LDVertex*> (this)->pos += vect;
 	}
 	else
 	{
-		for( int i = 0; i < vertices(); ++i)
-			setVertex( i, getVertex( i) + vect);
+		for (int i = 0; i < vertices(); ++i)
+			setVertex (i, getVertex (i) + vect);
 	}
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
 #define CHECK_FOR_OBJ(N) \
-	if( type == LDObject::N) \
+	if (type == LDObject::E##N) \
 		return new LD##N;
 
-LDObject* LDObject::getDefault( const LDObject::Type type)
+LDObject* LDObject::getDefault (const LDObject::Type type)
 {
-	CHECK_FOR_OBJ( Comment)
-	CHECK_FOR_OBJ( BFC)
-	CHECK_FOR_OBJ( Line)
-	CHECK_FOR_OBJ( CondLine)
-	CHECK_FOR_OBJ( Subfile)
-	CHECK_FOR_OBJ( Triangle)
-	CHECK_FOR_OBJ( Quad)
-	CHECK_FOR_OBJ( Empty)
-	CHECK_FOR_OBJ( BFC)
-	CHECK_FOR_OBJ( Error)
-	CHECK_FOR_OBJ( Vertex)
-	CHECK_FOR_OBJ( Overlay)
+	CHECK_FOR_OBJ (Comment)
+	CHECK_FOR_OBJ (BFC)
+	CHECK_FOR_OBJ (Line)
+	CHECK_FOR_OBJ (CondLine)
+	CHECK_FOR_OBJ (Subfile)
+	CHECK_FOR_OBJ (Triangle)
+	CHECK_FOR_OBJ (Quad)
+	CHECK_FOR_OBJ (Empty)
+	CHECK_FOR_OBJ (BFC)
+	CHECK_FOR_OBJ (Error)
+	CHECK_FOR_OBJ (Vertex)
+	CHECK_FOR_OBJ (Overlay)
 	return null;
 }
 
@@ -573,9 +573,9 @@
 {
 	// Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1.
 	// Thus, we swap 1 and 2.
-	vertex tmp = getVertex( 1);
-	setVertex( 1, getVertex( 2));
-	setVertex( 2, tmp);
+	Vertex tmp = getVertex (1);
+	setVertex (1, getVertex (2));
+	setVertex (2, tmp);
 
 	return;
 }
@@ -587,9 +587,9 @@
 	// Quad: 0 -> 1 -> 2 -> 3
 	// rev:  0 -> 3 -> 2 -> 1
 	// Thus, we swap 1 and 3.
-	vertex tmp = getVertex( 1);
-	setVertex( 1, getVertex( 3));
-	setVertex( 3, tmp);
+	Vertex tmp = getVertex (1);
+	setVertex (1, getVertex (3));
+	setVertex (3, tmp);
 }
 
 // =============================================================================
@@ -604,11 +604,11 @@
 
 	int idx = getIndex();
 
-	if( idx > 0)
+	if (idx > 0)
 	{
-		LDBFC* bfc = dynamic_cast<LDBFC*>( prev());
+		LDBFC* bfc = dynamic_cast<LDBFC*> (prev());
 
-		if( bfc && bfc->type == LDBFC::InvertNext)
+		if (bfc && bfc->type == LDBFC::InvertNext)
 		{
 			// This is prefixed with an invertnext, thus remove it.
 			bfc->deleteSelf();
@@ -617,29 +617,29 @@
 	}
 
 	// Not inverted, thus prefix it with a new invertnext.
-	LDBFC* bfc = new LDBFC( LDBFC::InvertNext);
-	getFile()->insertObj( idx, bfc);
+	LDBFC* bfc = new LDBFC (LDBFC::InvertNext);
+	getFile()->insertObj (idx, bfc);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-static void invertLine( LDObject* line)
+static void invertLine (LDObject* line)
 {
 	// For lines, we swap the vertices. I don't think that a
 	// cond-line's control points need to be swapped, do they?
-	vertex tmp = line->getVertex( 0);
-	line->setVertex( 0, line->getVertex( 1));
-	line->setVertex( 1, tmp);
+	Vertex tmp = line->getVertex (0);
+	line->setVertex (0, line->getVertex (1));
+	line->setVertex (1, tmp);
 }
 
 void LDLine::invert()
 {
-	invertLine( this);
+	invertLine (this);
 }
 
 void LDCondLine::invert()
 {
-	invertLine( this);
+	invertLine (this);
 }
 
 void LDVertex::invert() {}
@@ -650,21 +650,21 @@
 {
 	LDLine* repl = new LDLine;
 
-	for( int i = 0; i < repl->vertices(); ++i)
-		repl->setVertex( i, getVertex( i));
+	for (int i = 0; i < repl->vertices(); ++i)
+		repl->setVertex (i, getVertex (i));
 
-	repl->setColor( getColor());
+	repl->setColor (getColor());
 
-	replace( repl);
+	replace (repl);
 	return repl;
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-LDObject* LDObject::fromID( int id)
+LDObject* LDObject::fromID (int id)
 {
-	for( LDObject* obj : g_LDObjects)
-		if( obj->getID() == id)
+	for (LDObject* obj : g_LDObjects)
+		if (obj->getID() == id)
 			return obj;
 
 	return null;
@@ -674,7 +674,7 @@
 // -----------------------------------------------------------------------------
 str LDOverlay::raw() const
 {
-	return fmt( "0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6",
+	return fmt ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6",
 		getFileName(), getCamera(), getX(), getY(), getWidth(), getHeight());
 }
 
@@ -685,21 +685,21 @@
 // It takes care of history management so we can capture low-level changes, this
 // makes history stuff work out of the box.
 // -----------------------------------------------------------------------------
-template<class T> static void changeProperty( LDObject* obj, T* ptr, const T& val)
+template<class T> static void changeProperty (LDObject* obj, T* ptr, const T& val)
 {
 	long idx;
 
-	if( *ptr == val)
+	if (*ptr == val)
 		return;
 
-	if( obj->getFile() &&( idx = obj->getIndex()) != -1)
+	if (obj->getFile() && (idx = obj->getIndex()) != -1)
 	{
 		str before = obj->raw();
 		*ptr = val;
 		str after = obj->raw();
 
-		if( before != after)
-			obj->getFile()->addToHistory( new EditHistory( idx, before, after));
+		if (before != after)
+			obj->getFile()->addToHistory (new EditHistory (idx, before, after));
 	}
 	else
 		*ptr = val;
@@ -707,50 +707,50 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDObject::setColor( const int& val)
+void LDObject::setColor (const int& val)
 {
-	changeProperty( this, &m_Color, val);
+	changeProperty (this, &m_Color, val);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-const vertex& LDObject::getVertex( int i) const
+const Vertex& LDObject::getVertex (int i) const
 {
 	return m_coords[i]->data();
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDObject::setVertex( int i, const vertex& vert)
+void LDObject::setVertex (int i, const Vertex& vert)
 {
-	changeProperty( this, &m_coords[i], LDSharedVertex::getSharedVertex( vert));
+	changeProperty (this, &m_coords[i], LDSharedVertex::getSharedVertex (vert));
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDMatrixObject::setPosition( const vertex& a)
+void LDMatrixObject::setPosition (const Vertex& a)
 {
-	changeProperty( getLinkPointer(), &m_Position, LDSharedVertex::getSharedVertex( a));
+	changeProperty (getLinkPointer(), &m_Position, LDSharedVertex::getSharedVertex (a));
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDMatrixObject::setTransform( const matrix& val)
+void LDMatrixObject::setTransform (const Matrix& val)
 {
-	changeProperty( getLinkPointer(), &m_Transform, val);
+	changeProperty (getLinkPointer(), &m_Transform, val);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-static QMap<vertex, LDSharedVertex*> g_sharedVerts;
+static QMap<Vertex, LDSharedVertex*> g_sharedVerts;
 
-LDSharedVertex* LDSharedVertex::getSharedVertex( const vertex& a)
+LDSharedVertex* LDSharedVertex::getSharedVertex (const Vertex& a)
 {
-	auto it = g_sharedVerts.find( a);
+	auto it = g_sharedVerts.find (a);
 
-	if( it == g_sharedVerts.end())
+	if (it == g_sharedVerts.end())
 	{
-		LDSharedVertex* v = new LDSharedVertex( a);
+		LDSharedVertex* v = new LDSharedVertex (a);
 		g_sharedVerts[a] = v;
 		return v;
 	}
@@ -760,20 +760,20 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDSharedVertex::addRef( LDObject* a)
+void LDSharedVertex::addRef (LDObject* a)
 {
 	m_refs << a;
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void LDSharedVertex::delRef( LDObject* a)
+void LDSharedVertex::delRef (LDObject* a)
 {
-	m_refs.removeOne( a);
+	m_refs.removeOne (a);
 
-	if( m_refs.empty())
+	if (m_refs.empty())
 	{
-		g_sharedVerts.remove( m_data);
+		g_sharedVerts.remove (m_data);
 		delete this;
 	}
 }
@@ -782,33 +782,33 @@
 // -----------------------------------------------------------------------------
 void LDObject::select()
 {
-	if( !getFile())
+	if (!getFile())
 	{
-		log( "Warning: Object #%1 cannot be selected as it is not assigned a file!\n", getID());
+		log ("Warning: Object #%1 cannot be selected as it is not assigned a file!\n", getID());
 		return;
 	}
 
-	getFile()->addToSelection( this);
+	getFile()->addToSelection (this);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
 void LDObject::unselect()
 {
-	if( !getFile())
+	if (!getFile())
 	{
-		log( "Warning: Object #%1 cannot be unselected as it is not assigned a file!\n", getID());
+		log ("Warning: Object #%1 cannot be unselected as it is not assigned a file!\n", getID());
 		return;
 	}
 
-	getFile()->removeFromSelection( this);
+	getFile()->removeFromSelection (this);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-str getLicenseText( int id)
+str getLicenseText (int id)
 {
-	switch( id)
+	switch (id)
 	{
 		case 0:
 			return CALicense;
@@ -820,7 +820,7 @@
 			return "";
 	}
 
-	assert( false);
+	assert (false);
 	return "";
 }
 
@@ -830,41 +830,41 @@
 {
 	/*
 	LDObject* copy = clone();
-	copy->setFile( null);
-	copy->setGLInit( false);
+	copy->setFile (null);
+	copy->setGLInit (false);
 	copy->chooseID();
-	copy->setSelected( false);
+	copy->setSelected (false);
 	*/
 
 	/*
-	LDObject* copy = getDefault( getType());
-	copy->setColor( getColor());
+	LDObject* copy = getDefault (getType());
+	copy->setColor (getColor());
 
-	if( hasMatrix())
+	if (hasMatrix())
 	{
-		LDMatrixObject* copyMo = static_cast<LDMatrixObject*>( copy);
-		const LDMatrixObject* mo = static_cast<const LDMatrixObject*>( this);
-		copyMo->setPosition( mo->getPosition());
-		copyMo->setTransform( mo->getTransform());
+		LDMatrixObject* copyMo = static_cast<LDMatrixObject*> (copy);
+		const LDMatrixObject* mo = static_cast<const LDMatrixObject*> (this);
+		copyMo->setPosition (mo->getPosition());
+		copyMo->setTransform (mo->getTransform());
 	}
 	else
 	{
-		for( int i = 0; i < vertices(); ++i)
-			copy->setVertex( getVertex( i));
+		for (int i = 0; i < vertices(); ++i)
+			copy->setVertex (getVertex (i));
 	}
 
-	switch( getType())
+	switch (getType())
 	{
 		case Subfile:
 		{
-			LDSubfile* copyRef = static_cast<LDSubfile*>( copy);
-			const LDSubfile* ref = static_cast<const LDSubfile*>( this);
+			LDSubfile* copyRef = static_cast<LDSubfile*> (copy);
+			const LDSubfile* ref = static_cast<const LDSubfile*> (this);
 
-			copyRef->setFileInfo( ref->getFileInfo());
+			copyRef->setFileInfo (ref->getFileInfo());
 		}
 	}
 	*/
 
-	LDObject* copy = parseLine( raw());
+	LDObject* copy = parseLine (raw());
 	return copy;
 }
\ No newline at end of file

mercurial