more restyle/refactor

Sun, 07 Jul 2013 17:45:48 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 07 Jul 2013 17:45:48 +0300
changeset 359
bcdfc801658b
parent 358
7885fa5b09c5
child 360
77f08db90249

more restyle/refactor

src/bbox.cpp file | annotate | diff | comparison | revisions
src/bbox.h file | annotate | diff | comparison | revisions
src/colors.cpp file | annotate | diff | comparison | revisions
src/colors.h file | annotate | diff | comparison | revisions
src/config.cpp file | annotate | diff | comparison | revisions
src/config.h file | annotate | diff | comparison | revisions
src/ldtypes.cpp file | annotate | diff | comparison | revisions
--- a/src/bbox.cpp	Sun Jul 07 16:46:30 2013 +0300
+++ b/src/bbox.cpp	Sun Jul 07 17:45:48 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 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.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -24,48 +24,54 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-bbox::bbox () {
-	reset ();
+bbox::bbox()
+{
+	reset();
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void bbox::calculate () {
-	reset ();
+void bbox::calculate()
+{
+	reset();
 	
-	if (!g_curfile)
+	if( !g_curfile )
 		return;
 	
-	for (LDObject* obj : g_curfile->objs ())
-		calcObject (obj);
+	for( LDObject* obj : g_curfile->objs() )
+		calcObject( obj );
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void bbox::calcObject (LDObject* obj) {
-	switch (obj->getType ()) {
+void bbox::calcObject( LDObject* obj )
+{
+	switch( obj->getType() )
+	{
 	case LDObject::Line:
 	case LDObject::Triangle:
 	case LDObject::Quad:
 	case LDObject::CondLine:
-		for (short i = 0; i < obj->vertices (); ++i)
-			calcVertex (obj->getVertex (i));
+		for( short i = 0; i < obj->vertices(); ++i )
+			calcVertex( obj->getVertex( i ) );
+		
 		break;
-	
+
 	case LDObject::Subfile:
 		{
-			LDSubfile* ref = static_cast<LDSubfile*> (obj);
-			vector<LDObject*> objs = ref->inlineContents (true, true);
+			LDSubfile* ref = static_cast<LDSubfile*>( obj );
+			vector<LDObject*> objs = ref->inlineContents( true, true );
 			
-			for (LDObject* obj : objs) {
-				calcObject (obj);
+			for( LDObject * obj : objs )
+			{
+				calcObject( obj );
 				delete obj;
 			}
 		}
 		break;
-	
+
 	default:
 		break;
 	}
@@ -74,12 +80,14 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void bbox::calcVertex (const vertex& v) {
-	for (const Axis ax : g_Axes) {
-		if (v[ax] < m_v0[ax])
+void bbox::calcVertex( const vertex& v )
+{
+	for( const Axis ax : g_Axes )
+	{
+		if( v[ax] < m_v0[ax] )
 			m_v0[ax] = v[ax];
 		
-		if (v[ax] > m_v1[ax])
+		if( v[ax] > m_v1[ax] )
 			m_v1[ax] = v[ax];
 	}
 	
@@ -89,9 +97,10 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void bbox::reset () {
-	m_v0[X] = m_v0[Y] = m_v0[Z] = +0x7FFFFFFF;
-	m_v1[X] = m_v1[Y] = m_v1[Z] = -0x7FFFFFFF;
+void bbox::reset()
+{
+	m_v0[X] = m_v0[Y] = m_v0[Z] = 0x7FFFFFFF;
+	m_v1[X] = m_v1[Y] = m_v1[Z] = 0xFFFFFFFF;
 	
 	m_empty = true;
 }
@@ -99,28 +108,32 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-double bbox::size () const {
-	double fXScale = (m_v0[X] - m_v1[X]);
-	double fYScale = (m_v0[Y] - m_v1[Y]);
-	double fZScale = (m_v0[Z] - m_v1[Z]);
-	double fSize = fZScale;
+double bbox::size() const
+{
+	double xscale = ( m_v0[X] - m_v1[X] );
+	double yscale = ( m_v0[Y] - m_v1[Y] );
+	double zscale = ( m_v0[Z] - m_v1[Z] );
+	double size = zscale;
 	
-	if (fXScale > fYScale) {
-		if (fXScale > fZScale)
-			fSize = fXScale;
-	} elif (fYScale > fZScale)
-		fSize = fYScale;
+	if( xscale > yscale )
+	{
+		if( xscale > zscale )
+			size = xscale;
+	}
+	elif( yscale > zscale )
+		size = yscale;
 	
-	if (abs (fSize) >= 2.0f)
-		return abs (fSize / 2);
+	if( abs( size ) >= 2.0f )
+		return abs( size / 2 );
 	
 	return 1.0f;
 }
 
 // =============================================================================
-vertex bbox::center () const {
-	return vertex (
-		(m_v0[X] + m_v1[X]) / 2,
-		(m_v0[Y] + m_v1[Y]) / 2,
-		(m_v0[Z] + m_v1[Z]) / 2);
-}
\ No newline at end of file
+vertex bbox::center() const
+{
+	return vertex(
+		( m_v0[X] + m_v1[X] ) / 2,
+		( m_v0[Y] + m_v1[Y] ) / 2,
+		( m_v0[Z] + m_v1[Z] ) / 2 );
+}
--- a/src/bbox.h	Sun Jul 07 16:46:30 2013 +0300
+++ b/src/bbox.h	Sun Jul 07 17:45:48 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 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.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -29,29 +29,32 @@
 // global instance g_BBox is the bbox for the model we have open.
 // v0 is the minimum vertex, v1 is the maximum vertex.
 // =============================================================================
-class bbox {
-	READ_PROPERTY (bool, empty, setEmpty)
-	READ_PROPERTY (vertex, v0, setV0)
-	READ_PROPERTY (vertex, v1, setV1)
+class bbox
+{
+	READ_PROPERTY( bool, empty, setEmpty )
+	READ_PROPERTY( vertex, v0, setV0 )
+	READ_PROPERTY( vertex, v1, setV1 )
 	
 public:
-	bbox ();
-	void reset ();
-	void calculate ();
-	double size () const;
-	void calcObject (LDObject* obj);
-	void calcVertex (const vertex& v);
-	vertex center () const;
+	bbox();
+	void reset();
+	void calculate();
+	double size() const;
+	void calcObject( LDObject* obj );
+	void calcVertex( const vertex& v );
+	vertex center() const;
 	
-	bbox& operator<< (LDObject* obj) {
-		calcObject (obj);
+	bbox& operator<< ( LDObject* obj )
+	{
+		calcObject( obj );
 		return *this;
 	}
 	
-	bbox& operator<< (const vertex& v) {
-		calcVertex (v);
+	bbox& operator<< ( const vertex& v )
+	{
+		calcVertex( v );
 		return *this;
 	}
 };
 
-#endif // BBOX_H
\ No newline at end of file
+#endif // BBOX_H
--- a/src/colors.cpp	Sun Jul 07 16:46:30 2013 +0300
+++ b/src/colors.cpp	Sun Jul 07 17:45:48 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 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.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -25,8 +25,9 @@
 
 static color* g_LDColors[MAX_COLORS];
 
-void initColors () {
-	print ("%1: initializing color information.\n", __func__);
+void initColors()
+{
+	print( "%1: initializing color information.\n", __func__ );
 	
 	color* col;
 	
@@ -42,47 +43,51 @@
 	col->edgeColor = col->faceColor = Qt::black;
 	g_LDColors[edgecolor] = col;
 	
-	parseLDConfig ();
+	parseLDConfig();
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-color* getColor (short dColorNum) {
+color* getColor( short colnum )
+{
 	// Check bounds
-	if (dColorNum < 0 || dColorNum >= MAX_COLORS)
+	if( colnum < 0 || colnum >= MAX_COLORS )
 		return null;
 	
-	return g_LDColors[dColorNum];
+	return g_LDColors[colnum];
 }
 
 // =============================================================================
-uchar luma (QColor& col) {
-	return (0.2126f * col.red ()) +
-		(0.7152f * col.green ()) +
-		(0.0722f * col.blue ());
+uchar luma( QColor& col )
+{
+	return ( 0.2126f * col.red()) +
+	       ( 0.7152f * col.green()) +
+	       ( 0.0722f * col.blue() );
 }
 
 // =============================================================================
 // Helper function for parseLDConfig
-static bool parseLDConfigTag (StringParser& pars, char const* tag, str& val) {
+static bool parseLDConfigTag( StringParser& pars, char const* tag, str& val )
+{
 	short pos;
-	
+
 	// Try find the token and get its position
-	if (!pars.findToken (pos, tag, 1))
+	if( !pars.findToken( pos, tag, 1 ))
 		return false;
-	
+
 	// Get the token after it and store it into val
-	return pars.getToken (val, pos + 1);
+	return pars.getToken( val, pos + 1 );
 }
 
 // =============================================================================
-void parseLDConfig () {
-	File* f = openLDrawFile ("LDConfig.ldr", false);
+void parseLDConfig()
+{
+	File* f = openLDrawFile( "LDConfig.ldr", false );
 	
-	if ( !f )
+	if( !f )
 	{
-		critical( fmt( QObject::tr( "Unable to open LDConfig.ldr for parsing! (%1)" ), strerror( errno )));
+		critical( fmt( QObject::tr( "Unable to open LDConfig.ldr for parsing! (%1)" ), strerror( errno )) );
 		delete f;
 		return;
 	}
@@ -90,62 +95,63 @@
 	// Read in the lines
 	for( str line : *f )
 	{
-		if (line.length () == 0 || line[0] != '0')
+		if( line.length() == 0 || line[0] != '0' )
 			continue; // empty or illogical
 		
-		line.remove ('\r');
-		line.remove ('\n');
+		line.remove( '\r' );
+		line.remove( '\n' );
 		
 		// Parse the line
-		StringParser pars (line, ' ');
+		StringParser pars( line, ' ' );
 		
 		short code = 0, alpha = 255;
 		str name, facename, edgename, valuestr;
 		
 		// Check 0 !COLOUR, parse the name
-		if (!pars.tokenCompare (0, "0") || !pars.tokenCompare (1, "!COLOUR") || !pars.getToken (name, 2))
+		if( !pars.tokenCompare( 0, "0" ) || !pars.tokenCompare( 1, "!COLOUR" ) || !pars.getToken( name, 2 ))
 			continue;
 		
 		// Replace underscores in the name with spaces for readability
-		name.replace ("_", " ");
+		name.replace( "_", " " );
 		
 		// Get the CODE tag
-		if (!parseLDConfigTag (pars, "CODE", valuestr))
+		if( !parseLDConfigTag( pars, "CODE", valuestr ))
 			continue;
 		
-		if (!isNumber (valuestr))
+		if( !isNumber( valuestr ))
 			continue; // not a number
 		
 		// Ensure that the code is within [0 - 511]
 		bool ok;
-		code = valuestr.toShort (&ok);
-		if (!ok || code < 0 || code >= 512)
+		code = valuestr.toShort( &ok );
+		
+		if( !ok || code < 0 || code >= 512 )
 			continue;
 		
 		// VALUE and EDGE tags
-		if (!parseLDConfigTag (pars, "VALUE", facename) || !parseLDConfigTag (pars, "EDGE", edgename))
+		if( !parseLDConfigTag( pars, "VALUE", facename ) || !parseLDConfigTag( pars, "EDGE", edgename ))
 			continue;
 		
 		// Ensure that our colors are correct
-		QColor faceColor (facename),
-			edgeColor (edgename);
+		QColor faceColor( facename ),
+			edgeColor( edgename );
 		
-		if (!faceColor.isValid () || !edgeColor.isValid ())
+		if( !faceColor.isValid() || !edgeColor.isValid() )
 			continue;
 		
 		// Parse alpha if given.
-		if (parseLDConfigTag (pars, "ALPHA", valuestr))
-			alpha = clamp<short> (valuestr.toShort (), 0, 255);
+		if( parseLDConfigTag( pars, "ALPHA", valuestr ))
+			alpha = clamp<short> ( valuestr.toShort(), 0, 255 );
 		
 		color* col = new color;
 		col->name = name;
 		col->faceColor = faceColor;
 		col->edgeColor = edgeColor;
 		col->hexcode = facename;
-		col->faceColor.setAlpha (alpha);
+		col->faceColor.setAlpha( alpha );
 		col->index = code;
 		g_LDColors[code] = col;
 	}
 	
 	delete f;
-}
\ No newline at end of file
+}
--- a/src/colors.h	Sun Jul 07 16:46:30 2013 +0300
+++ b/src/colors.h	Sun Jul 07 17:45:48 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 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.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -24,18 +24,19 @@
 
 #define MAX_COLORS 512
 
-class color {
+class color
+{
 public:
 	str name, hexcode;
 	QColor faceColor, edgeColor;
 	short index;
 };
 
-void initColors ();
-void parseLDConfig ();
-uchar luma (QColor& col);
+void initColors();
+void parseLDConfig();
+uchar luma( QColor& col );
 
 // Safely gets a color with the given number or null if no such color.
-color* getColor (short dColorNum);
+color* getColor( short colnum );
 
-#endif // COLORS_H
\ No newline at end of file
+#endif // COLORS_H
--- a/src/config.cpp	Sun Jul 07 16:46:30 2013 +0300
+++ b/src/config.cpp	Sun Jul 07 17:45:48 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 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.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -19,7 +19,7 @@
 #include <errno.h>
 #include <time.h>
 #include <QDir>
-#include <qtextstream.h>
+#include <QTextStream>
 #include "common.h"
 #include "config.h"
 #include "misc.h"
@@ -30,77 +30,86 @@
 
 // =============================================================================
 // Load the configuration from file
-bool config::load () {
-	print ("config::load: Loading configuration file...\n");
-	print ("config::load: Path to configuration is %1\n", filepath ());
+bool config::load()
+{
+	print( "config::load: Loading configuration file...\n" );
+	print( "config::load: Path to configuration is %1\n", filepath() );
 	
 	// Locale must be disabled for atof
-	setlocale (LC_NUMERIC, "C");
+	setlocale( LC_NUMERIC, "C" );
 	
-	File f (filepath (), File::Read);
-	if (!f)
+	File f( filepath(), File::Read );
+	int ln = 0;
+	
+	if( !f )
 		return false;
 	
-	size_t ln = 0;
-	
 	// Read the values.
-	for (str line : f) {
+	for( str line : f )
+	{
 		ln++;
 		
-		if (line.isEmpty () || line[0] == '#')
+		if( line.isEmpty() || line[0] == '#' )
 			continue; // Empty line or comment.
 		
 		// Find the equals sign.
-		int equals = line.indexOf ('=');
-		if (equals == -1) {
-			fprint (stderr, "couldn't find `=` sign in entry `%1`\n", line);
+		int equals = line.indexOf( '=' );
+		
+		if( equals == -1 )
+		{
+			fprint( stderr, "couldn't find `=` sign in entry `%1`\n", line );
 			continue;
 		}
 		
-		str entry = line.left (equals);
-		str valstring = line.right (line.length () - equals - 1);
+		str entry = line.left( equals );
+		str valstring = line.right( line.length() - equals - 1 );
 		
 		// Find the config entry for this.
 		config* cfg = null;
-		for (config* i : g_configPointers) {
-			if (!i)
+		
+		for( config* i : g_configPointers )
+		{
+			if( !i )
 				break;
 			
-			if (entry == i->name)
+			if( entry == i->name )
 				cfg = i;
 		}
 		
-		if (!cfg) {
-			fprint (stderr, "unknown config `%1`\n", entry);
+		if( !cfg )
+		{
+			fprint( stderr, "unknown config `%1`\n", entry );
 			continue;
 		}
 		
-		switch (cfg->getType()) {
-		case CONFIG_int:
-			static_cast<intconfig*> (cfg)->value = valstring.toInt ();
+		switch( cfg->getType() )
+		{
+		case Type_int:
+			static_cast<intconfig*>( cfg )->value = valstring.toInt();
 			break;
 		
-		case CONFIG_str:
-			static_cast<strconfig*> (cfg)->value = valstring;
+		case Type_str:
+			static_cast<strconfig*>( cfg )->value = valstring;
 			break;
 		
-		case CONFIG_float:
-			static_cast<floatconfig*> (cfg)->value = valstring.toFloat ();
+		case Type_float:
+			static_cast<floatconfig*>( cfg )->value = valstring.toFloat();
 			break;
 		
-		case CONFIG_bool:
+		case Type_bool:
 		{
-			bool& val = static_cast<boolconfig*> (cfg)->value;
+			bool& val = static_cast<boolconfig*>( cfg )->value;
 			
-			if (valstring.toUpper () == "TRUE" || valstring == "1")
+			if( valstring.toUpper() == "TRUE" || valstring == "1" )
 				val = true;
-			elif (valstring.toUpper () == "FALSE" || valstring == "0")
+			elif( valstring.toUpper() == "FALSE" || valstring == "0" )
 				val = false;
+			
 			break;
 		}
 		
-		case CONFIG_keyseq:
-			static_cast<keyseqconfig*> (cfg)->value = keyseq::fromString (valstring);
+		case Type_keyseq:
+			static_cast<keyseqconfig*>( cfg )->value = keyseq::fromString( valstring );
 			break;
 		
 		default:
@@ -108,66 +117,74 @@
 		}
 	}
 	
-	f.close ();
+	f.close();
 	return true;
 }
 
-extern_cfg (str, io_ldpath);
+extern_cfg( str, io_ldpath );
 
 // =============================================================================
 // Save the configuration to disk
-bool config::save () {
+bool config::save()
+{
 	// The function will write floats, disable the locale now so that they
 	// are written properly.
-	setlocale (LC_NUMERIC, "C");
+	setlocale( LC_NUMERIC, "C" );
 	
 	// If the directory doesn't exist, create it now.
-	if (QDir (dirpath ()).exists () == false) {
-		fprint (stderr, "Creating config path %1...\n", dirpath ());
-		if (!QDir ().mkpath (dirpath ())) {
-			critical ("Failed to create the configuration directory. Configuration cannot be saved!\n");
+	if( QDir( dirpath() ).exists() == false )
+	{
+		fprint( stderr, "Creating config path %1...\n", dirpath() );
+		
+		if( !QDir().mkpath( dirpath() ))
+		{
+			critical( "Failed to create the configuration directory. Configuration cannot be saved!\n" );
 			return false;
 		}
 	}
 	
-	File f (filepath (), File::Write);
-	print ("writing cfg to %1\n", filepath ());
+	File f( filepath(), File::Write );
+	print( "writing cfg to %1\n", filepath() );
 	
-	if (!f) {
+	if( !f )
+	{
 		critical( fmt( QObject::tr( "Cannot save configuration, cannot open %1 for writing: %2\n" ),
-			filepath(), strerror( errno )));
+			filepath(), strerror( errno )) );
 		return false;
 	}
 	
-	fprint (f, "# Configuration file for " APPNAME "\n");
+	fprint( f, "# Configuration file for " APPNAME "\n" );
 	
-	for (config* cfg : g_configPointers) {
-		if (!cfg)
+	for( config * cfg : g_configPointers )
+	{
+		if( !cfg )
 			break;
 		
-		if (cfg->isDefault ())
+		if( cfg->isDefault() )
 			continue;
 		
 		str valstring;
-		switch (cfg->getType ()) {
-		case CONFIG_int:
-			valstring = fmt ("%1", static_cast<intconfig*> (cfg)->value);
+		
+		switch( cfg->getType() )
+		{
+		case Type_int:
+			valstring = fmt( "%1", static_cast<intconfig*>( cfg )->value );
 			break;
 		
-		case CONFIG_str:
-			valstring = static_cast<strconfig*> (cfg)->value;
+		case Type_str:
+			valstring = static_cast<strconfig*>( cfg )->value;
 			break;
 		
-		case CONFIG_float:
-			valstring = fmt ("%1", static_cast<floatconfig*> (cfg)->value);
+		case Type_float:
+			valstring = fmt( "%1", static_cast<floatconfig*>( cfg )->value );
 			break;
 		
-		case CONFIG_bool:
-			valstring = (static_cast<boolconfig*> (cfg)->value) ? "true" : "false";
+		case Type_bool:
+			valstring = ( static_cast<boolconfig*>( cfg )->value ) ? "true" : "false";
 			break;
 		
-		case CONFIG_keyseq:
-			valstring = static_cast<keyseqconfig*> (cfg)->value.toString ();
+		case Type_keyseq:
+			valstring = static_cast<keyseqconfig*>( cfg )->value.toString();
 			break;
 		
 		default:
@@ -175,44 +192,49 @@
 		}
 		
 		// Write the entry now.
-		fprint (f, "%1=%2\n", cfg->name, valstring);
+		fprint( f, "%1=%2\n", cfg->name, valstring );
 	}
 	
-	f.close ();
+	f.close();
 	return true;
 }
 
 // =============================================================================
-void config::reset () {
-	for (config* cfg : g_configPointers) {
-		if (!cfg)
+void config::reset()
+{
+	for( config * cfg : g_configPointers )
+	{
+		if( !cfg )
 			break;
 		
-		cfg->resetValue ();
+		cfg->resetValue();
 	}
 }
 
 // =============================================================================
-str config::filepath () {
-	str path = fmt ("%1%2.cfg", dirpath (),
-		str (APPNAME).toLower ());
+str config::filepath()
+{
+	str path = fmt( "%1%2.cfg", dirpath(),
+		str( APPNAME ).toLower() );
 	return path;
 }
 
 // =============================================================================
-str config::dirpath () {
+str config::dirpath()
+{
 #ifndef _WIN32
-	return fmt ("%1" DIRSLASH ".%2" DIRSLASH,
-		QDir::homePath (), str (APPNAME).toLower ());
+	return fmt( "%1" DIRSLASH ".%2" DIRSLASH,
+				QDir::homePath(), str( APPNAME ).toLower() );
 #else
-	return fmt ("%1" DIRSLASH APPNAME DIRSLASH, QDir::homePath ());
+	return fmt( "%1" DIRSLASH APPNAME DIRSLASH, QDir::homePath() );
 #endif // _WIN32
 }
 
-void addConfig (config* ptr) {
-	if (g_cfgPointerCursor == 0)
-		memset (g_configPointers, 0, sizeof g_configPointers);
+void addConfig( config* ptr )
+{
+	if( g_cfgPointerCursor == 0 )
+		memset( g_configPointers, 0, sizeof g_configPointers );
 	
-	assert (g_cfgPointerCursor < MAX_CONFIG);
+	assert( g_cfgPointerCursor < MAX_CONFIG );
 	g_configPointers[g_cfgPointerCursor++] = ptr;
-}
\ No newline at end of file
+}
--- a/src/config.h	Sun Jul 07 16:46:30 2013 +0300
+++ b/src/config.h	Sun Jul 07 17:45:48 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 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.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -31,189 +31,203 @@
 #define MAX_INI_LINE 512
 #define MAX_CONFIG 512
 
-#define cfg(T, NAME, DEFAULT) \
-	T##config NAME (DEFAULT, #NAME)
-
-#define extern_cfg(T, NAME) \
-	extern T##config NAME
-
-// =============================================================================
-enum configtype_e {
-	CONFIG_none,
-	CONFIG_int,
-	CONFIG_str,
-	CONFIG_float,
-	CONFIG_bool,
-	CONFIG_keyseq,
-};
+#define cfg( T, NAME, DEFAULT ) T##config NAME (DEFAULT, #NAME)
+#define extern_cfg( T, NAME )   extern T##config NAME
 
 // =========================================================
-class config {
+class config
+{
 public:
+	enum Type
+	{
+		Type_none,
+		Type_int,
+		Type_str,
+		Type_float,
+		Type_bool,
+		Type_keyseq,
+	};
+
 	const char* name;
-	
-	virtual configtype_e getType () const {
-		return CONFIG_none;
+
+	virtual Type getType() const
+	{
+		return Type_none;
 	}
-	
-	virtual void resetValue () {}
-	virtual bool isDefault () const { return false; }
-	
+
+	virtual void resetValue() {}
+	virtual bool isDefault() const
+	{
+		return false;
+	}
+
 	// ------------------------------------------
-	static bool load ();
-	static bool save ();
-	static void reset ();
-	static str dirpath ();
-	static str filepath ();
+	static bool load();
+	static bool save();
+	static void reset();
+	static str dirpath();
+	static str filepath();
 };
 
-void addConfig (config* ptr);
+void addConfig( config* ptr );
 
 // =============================================================================
-#define DEFINE_UNARY_OPERATOR(T, OP) \
-	T operator OP () { \
-		return (OP value); \
+#define DEFINE_UNARY_OPERATOR( T, OP ) \
+	T operator OP() \
+	{ \
+		return OP value; \
 	} \
 
-#define DEFINE_BINARY_OPERATOR(T, OP) \
-	T operator OP (const T other) { \
-		return (value OP other); \
+#define DEFINE_BINARY_OPERATOR( T, OP ) \
+	T operator OP( const T other ) \
+	{ \
+		return value OP other; \
 	} \
 
-#define DEFINE_ASSIGN_OPERATOR(T, OP) \
-	T& operator OP (const T other) { \
-		return (value OP other); \
+#define DEFINE_ASSIGN_OPERATOR( T, OP ) \
+	T& operator OP( const T other ) \
+	{ \
+		return value OP other; \
 	} \
 
-#define DEFINE_COMPARE_OPERATOR(T, OP) \
-	bool operator OP (const T other) { \
-		return (value OP other); \
+#define DEFINE_COMPARE_OPERATOR( T, OP ) \
+	bool operator OP( const T other ) \
+	{ \
+		return value OP other; \
 	} \
 
-#define DEFINE_CAST_OPERATOR(T) \
-	operator T () { \
+#define DEFINE_CAST_OPERATOR( T ) \
+	operator T() \
+	{ \
 		return (T) value; \
 	} \
-
-#define DEFINE_ALL_COMPARE_OPERATORS(T) \
-	DEFINE_COMPARE_OPERATOR (T, ==) \
-	DEFINE_COMPARE_OPERATOR (T, !=) \
-	DEFINE_COMPARE_OPERATOR (T, >) \
-	DEFINE_COMPARE_OPERATOR (T, <) \
-	DEFINE_COMPARE_OPERATOR (T, >=) \
-	DEFINE_COMPARE_OPERATOR (T, <=) \
+	 
+#define DEFINE_ALL_COMPARE_OPERATORS( T ) \
+	DEFINE_COMPARE_OPERATOR( T, == ) \
+	DEFINE_COMPARE_OPERATOR( T, != ) \
+	DEFINE_COMPARE_OPERATOR( T, > ) \
+	DEFINE_COMPARE_OPERATOR( T, < ) \
+	DEFINE_COMPARE_OPERATOR( T, >= ) \
+	DEFINE_COMPARE_OPERATOR( T, <= ) \
+	 
+#define DEFINE_INCREMENT_OPERATORS( T ) \
+	T operator++() { return ++value; } \
+	T operator++(int) { return value++; } \
+	T operator--() { return --value; } \
+	T operator--(int) { return value--; }
 
-#define DEFINE_INCREMENT_OPERATORS(T) \
-	T operator++ () {return ++value;} \
-	T operator++ (int) {return value++;} \
-	T operator-- () {return --value;} \
-	T operator-- (int) {return value--;}
+#define CONFIGTYPE( T ) \
+	class T##config : public config
 
-#define CONFIGTYPE(T) \
-class T##config : public config
-
-#define IMPLEMENT_CONFIG(T) \
+#define IMPLEMENT_CONFIG( T ) \
 	T value, defval; \
 	\
 	T##config (T _defval, const char* _name) \
 	{ \
 		value = defval = _defval; \
 		name = _name; \
-		addConfig (this); \
+		addConfig( this ); \
 	} \
-	operator const T& () const { \
+	operator const T&() const \
+	{ \
 		return value; \
 	} \
-	configtype_e getType () const { \
-		return CONFIG_##T; \
+	config::Type getType() const \
+	{ \
+		return config::Type_##T; \
 	} \
-	virtual void resetValue () { \
+	virtual void resetValue() \
+	{ \
 		value = defval; \
 	} \
-	virtual bool isDefault () const { \
+	virtual bool isDefault() const \
+	{ \
 		return value == defval; \
 	}
 
 // =============================================================================
-CONFIGTYPE (int) {
+CONFIGTYPE( int )
+{
 public:
-	IMPLEMENT_CONFIG (int)
-	
-	// Int-specific operators
-	DEFINE_ALL_COMPARE_OPERATORS (int)
-	DEFINE_INCREMENT_OPERATORS (int)
-	DEFINE_BINARY_OPERATOR (int, +)
-	DEFINE_BINARY_OPERATOR (int, -)
-	DEFINE_BINARY_OPERATOR (int, *)
-	DEFINE_BINARY_OPERATOR (int, /)
-	DEFINE_BINARY_OPERATOR (int, %)
-	DEFINE_BINARY_OPERATOR (int, ^)
-	DEFINE_BINARY_OPERATOR (int, |)
-	DEFINE_BINARY_OPERATOR (int, &)
-	DEFINE_BINARY_OPERATOR (int, >>)
-	DEFINE_BINARY_OPERATOR (int, <<)
-	DEFINE_UNARY_OPERATOR (int, !)
-	DEFINE_UNARY_OPERATOR (int, ~)
-	DEFINE_UNARY_OPERATOR (int, -)
-	DEFINE_UNARY_OPERATOR (int, +)
-	DEFINE_ASSIGN_OPERATOR (int, =)
-	DEFINE_ASSIGN_OPERATOR (int, +=)
-	DEFINE_ASSIGN_OPERATOR (int, -=)
-	DEFINE_ASSIGN_OPERATOR (int, *=)
-	DEFINE_ASSIGN_OPERATOR (int, /=)
-	DEFINE_ASSIGN_OPERATOR (int, %=)
-	DEFINE_ASSIGN_OPERATOR (int, >>=)
-	DEFINE_ASSIGN_OPERATOR (int, <<=)
+	IMPLEMENT_CONFIG( int )
+	DEFINE_ALL_COMPARE_OPERATORS( int )
+	DEFINE_INCREMENT_OPERATORS( int )
+	DEFINE_BINARY_OPERATOR( int, + )
+	DEFINE_BINARY_OPERATOR( int, - )
+	DEFINE_BINARY_OPERATOR( int, * )
+	DEFINE_BINARY_OPERATOR( int, / )
+	DEFINE_BINARY_OPERATOR( int, % )
+	DEFINE_BINARY_OPERATOR( int, ^ )
+	DEFINE_BINARY_OPERATOR( int, | )
+	DEFINE_BINARY_OPERATOR( int, & )
+	DEFINE_BINARY_OPERATOR( int, >> )
+	DEFINE_BINARY_OPERATOR( int, << )
+	DEFINE_UNARY_OPERATOR( int, ! )
+	DEFINE_UNARY_OPERATOR( int, ~ )
+	DEFINE_UNARY_OPERATOR( int, - )
+	DEFINE_UNARY_OPERATOR( int, + )
+	DEFINE_ASSIGN_OPERATOR( int, = )
+	DEFINE_ASSIGN_OPERATOR( int, += )
+	DEFINE_ASSIGN_OPERATOR( int, -= )
+	DEFINE_ASSIGN_OPERATOR( int, *= )
+	DEFINE_ASSIGN_OPERATOR( int, /= )
+	DEFINE_ASSIGN_OPERATOR( int, %= )
+	DEFINE_ASSIGN_OPERATOR( int, >>= )
+	DEFINE_ASSIGN_OPERATOR( int, <<= )
 };
 
 // =============================================================================
-CONFIGTYPE (str) {
+CONFIGTYPE( str )
+{
 public:
-	IMPLEMENT_CONFIG (str)
+	IMPLEMENT_CONFIG( str )
+
+	DEFINE_COMPARE_OPERATOR( str, == )
+	DEFINE_COMPARE_OPERATOR( str, != )
+	DEFINE_ASSIGN_OPERATOR( str, = )
+	DEFINE_ASSIGN_OPERATOR( str, += )
 	
-	DEFINE_COMPARE_OPERATOR (str, ==)
-	DEFINE_COMPARE_OPERATOR (str, !=)
-	DEFINE_ASSIGN_OPERATOR (str, =)
-	DEFINE_ASSIGN_OPERATOR (str, +=)
-	
-	qchar operator[] (int n) {
+	qchar operator[]( int n )
+	{
 		return value[n];
 	}
 };
 
 // =============================================================================
-CONFIGTYPE (float) {
+CONFIGTYPE( float )
+{
 public:
-	IMPLEMENT_CONFIG (float)
-	
-	DEFINE_ALL_COMPARE_OPERATORS (float)
-	DEFINE_INCREMENT_OPERATORS (float)
-	DEFINE_BINARY_OPERATOR (float, +)
-	DEFINE_BINARY_OPERATOR (float, -)
-	DEFINE_BINARY_OPERATOR (float, *)
-	DEFINE_UNARY_OPERATOR (float, !)
-	DEFINE_ASSIGN_OPERATOR (float, =)
-	DEFINE_ASSIGN_OPERATOR (float, +=)
-	DEFINE_ASSIGN_OPERATOR (float, -=)
-	DEFINE_ASSIGN_OPERATOR (float, *=)
+	IMPLEMENT_CONFIG( float )
+	DEFINE_ALL_COMPARE_OPERATORS( float )
+	DEFINE_INCREMENT_OPERATORS( float )
+	DEFINE_BINARY_OPERATOR( float, + )
+	DEFINE_BINARY_OPERATOR( float, - )
+	DEFINE_BINARY_OPERATOR( float, * )
+	DEFINE_UNARY_OPERATOR( float, ! )
+	DEFINE_ASSIGN_OPERATOR( float, = )
+	DEFINE_ASSIGN_OPERATOR( float, += )
+	DEFINE_ASSIGN_OPERATOR( float, -= )
+	DEFINE_ASSIGN_OPERATOR( float, *= )
 };
 
 // =============================================================================
-CONFIGTYPE (bool) {
+CONFIGTYPE( bool )
+{
 public:
-	IMPLEMENT_CONFIG (bool)
-	DEFINE_ALL_COMPARE_OPERATORS (bool)
-	DEFINE_ASSIGN_OPERATOR (bool, =)
+	IMPLEMENT_CONFIG( bool )
+	DEFINE_ALL_COMPARE_OPERATORS( bool )
+	DEFINE_ASSIGN_OPERATOR( bool, = )
 };
 
 // =============================================================================
 typedef QKeySequence keyseq;
 
-CONFIGTYPE (keyseq) {
+CONFIGTYPE( keyseq )
+{
 public:
-	IMPLEMENT_CONFIG (keyseq)
-	DEFINE_ALL_COMPARE_OPERATORS (keyseq)
-	DEFINE_ASSIGN_OPERATOR (keyseq, =)
+	IMPLEMENT_CONFIG( keyseq )
+	DEFINE_ALL_COMPARE_OPERATORS( keyseq )
+	DEFINE_ASSIGN_OPERATOR( keyseq, = )
 };
 
-#endif // CONFIG_H
\ No newline at end of file
+#endif // CONFIG_H
--- a/src/ldtypes.cpp	Sun Jul 07 16:46:30 2013 +0300
+++ b/src/ldtypes.cpp	Sun Jul 07 17:45:48 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 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.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -31,16 +31,18 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 // LDObject constructors
-LDObject::LDObject () {
+LDObject::LDObject()
+{
 	qObjListEntry = null;
-	setParent (null);
+	setParent( null );
 	m_hidden = false;
 	m_selected = false;
 	m_glinit = false;
 	
 	// Determine ID
 	int id = 1; // 0 is invalid
-	for( LDObject* obj : g_LDObjects )
+	
+	for( LDObject * obj : g_LDObjects )
 		if( obj->id() >= id )
 			id = obj->id() + 1;
 	
@@ -49,75 +51,85 @@
 	g_LDObjects << this;
 }
 
-LDGibberish::LDGibberish () {}
-LDGibberish::LDGibberish (str contents, str reason) : contents (contents), reason (reason) {}
+LDGibberish::LDGibberish() {}
+LDGibberish::LDGibberish( str contents, str reason ) : contents( contents ), reason( reason ) {}
 
 // =============================================================================
-str LDComment::raw () {
-	return fmt ("0 %1", text);
+str LDComment::raw()
+{
+	return fmt( "0 %1", text );
 }
 
-str LDSubfile::raw () {
-	str val = fmt ("1 %1 %2 ", color (), position ());
-	val += transform ().stringRep ();
+str LDSubfile::raw()
+{
+	str val = fmt( "1 %1 %2 ", color(), position() );
+	val += transform().stringRep();
 	val += ' ';
-	val += fileInfo ()->name ();
+	val += fileInfo()->name();
 	return val;
 }
 
-str LDLine::raw () {
-	str val = fmt ("2 %1", color ());
+str LDLine::raw()
+{
+	str val = fmt( "2 %1", color() );
 	
-	for (ushort i = 0; i < 2; ++i)
-		val += fmt (" %1", getVertex (i));
+	for( ushort i = 0; i < 2; ++i )
+		val += fmt( " %1", getVertex( i ) );
 	
 	return val;
 }
 
-str LDTriangle::raw () {
-	str val = fmt ("3 %1", color ());
+str LDTriangle::raw()
+{
+	str val = fmt( "3 %1", color() );
 	
-	for (ushort i = 0; i < 3; ++i)
-		val += fmt  (" %1", getVertex (i));
+	for( ushort i = 0; i < 3; ++i )
+		val += fmt( " %1", getVertex( i ) );
 	
 	return val;
 }
 
-str LDQuad::raw () {
-	str val = fmt ("4 %1", color ());
+str LDQuad::raw()
+{
+	str val = fmt( "4 %1", color() );
 	
-	for (ushort i = 0; i < 4; ++i)
-		val += fmt  (" %1", getVertex (i));
+	for( ushort i = 0; i < 4; ++i )
+		val += fmt( " %1", getVertex( i ) );
 	
 	return val;
 }
 
-str LDCondLine::raw () {
-	str val = fmt ("5 %1", color ());
+str LDCondLine::raw()
+{
+	str val = fmt( "5 %1", color() );
 	
 	// Add the coordinates
-	for (ushort i = 0; i < 4; ++i)
-		val += fmt  (" %1", getVertex (i));
+	for( ushort i = 0; i < 4; ++i )
+		val += fmt( " %1", getVertex( i ) );
 	
 	return val;
 }
 
-str LDGibberish::raw () {
+str LDGibberish::raw()
+{
 	return contents;
 }
 
-str LDVertex::raw () {
-	return fmt ("0 !LDFORGE VERTEX %1 %2", color (), pos);
+str LDVertex::raw()
+{
+	return fmt( "0 !LDFORGE VERTEX %1 %2", color(), pos );
 }
 
-str LDEmpty::raw () {
-	return str ();
+str LDEmpty::raw()
+{
+	return "";
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-const char* LDBFC::statements[] = {
+const char* LDBFC::statements[] =
+{
 	"CERTIFY CCW",
 	"CCW",
 	"CERTIFY CW",
@@ -126,26 +138,28 @@
 	"INVERTNEXT",
 };
 
-str LDBFC::raw () {
-	return fmt ("0 BFC %1", LDBFC::statements[type]);
+str LDBFC::raw()
+{
+	return fmt( "0 BFC %1", LDBFC::statements[type] );
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-vector<LDTriangle*> LDQuad::splitToTriangles () {
+vector<LDTriangle*> LDQuad::splitToTriangles()
+{
 	// Create the two triangles based on this quadrilateral:
 	// 0---3     0---3    3
 	// |   |     |  /    /|
 	// |   |  =  | /    / |
 	// |   |     |/    /  |
 	// 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 (color ());
-	tri2->setColor (color ());
+	tri1->setColor( color() );
+	tri2->setColor( color() );
 	
 	vector<LDTriangle*> triangles;
 	triangles << tri1;
@@ -156,12 +170,13 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void LDObject::replace (LDObject* replacement) {
-	long idx = getIndex (g_curfile);
-	assert (idx != -1);
+void LDObject::replace( LDObject* replacement )
+{
+	long idx = getIndex( g_curfile );
+	assert( idx != -1 );
 	
 	// Replace the instance of the old object with the new object
-	g_curfile->setObject (idx, replacement);
+	g_curfile->setObject( idx, replacement );
 	
 	// Remove the old object
 	delete this;
@@ -170,60 +185,68 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void LDObject::swap (LDObject* other) {
-	for (LDObject*& obj : *g_curfile) {
-		if (obj == this)
+void LDObject::swap( LDObject* other )
+{
+	for( LDObject*& obj : *g_curfile )
+	{
+		if( obj == this )
 			obj = other;
-		elif (obj == other)
+		elif( obj == other )
 			obj = this;
 	}
 }
 
-LDLine::LDLine (vertex v1, vertex v2) {
-	setVertex (0, v1);
-	setVertex (1, v2);
+LDLine::LDLine( vertex v1, vertex v2 )
+{
+	setVertex( 0, v1 );
+	setVertex( 1, v2 );
 }
 
-LDObject::~LDObject () {
+LDObject::~LDObject()
+{
 	// Remove this object from the selection array if it is there.
-	for (ulong i = 0; i < g_win->sel().size(); ++i)
-		if (g_win->sel ()[i] == this)
-			g_win->sel ().erase (i);
+	for( ulong i = 0; i < g_win->sel().size(); ++i )
+		if( g_win->sel()[i] == this )
+			g_win->sel().erase( i );
 	
 	// Delete the GL lists
 	GL::deleteLists( this );
 	
 	// Remove this object from the list of LDObjects
 	ulong pos = g_LDObjects.find( this );
-	if( pos < g_LDObjects.size())
+	
+	if( pos < g_LDObjects.size() )
 		g_LDObjects.erase( pos );
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-static void transformObject (LDObject* obj, matrix transform, vertex pos, short parentcolor) {
-	switch (obj->getType()) {
+static void transformObject( LDObject* obj, matrix transform, vertex pos, short parentcolor )
+{
+	switch( obj->getType() )
+	{
 	case LDObject::Line:
 	case LDObject::CondLine:
 	case LDObject::Triangle:
 	case LDObject::Quad:
-		for (short i = 0; i < obj->vertices (); ++i) {
-			vertex v = obj->getVertex (i);
-			v.transform (transform, pos);
-			obj->setVertex (i, v);
+		for( short i = 0; i < obj->vertices(); ++i )
+		{
+			vertex v = obj->getVertex( i );
+			v.transform( transform, pos );
+			obj->setVertex( i, v );
 		}
 		break;
 	
 	case LDObject::Subfile:
 		{
-			LDSubfile* ref = static_cast<LDSubfile*> (obj);
-			matrix newMatrix = transform * ref->transform ();
-			vertex newpos = ref->position ();
+			LDSubfile* ref = static_cast<LDSubfile*>( obj );
+			matrix newMatrix = transform * ref->transform();
+			vertex newpos = ref->position();
 			
-			newpos.transform (transform, pos);
-			ref->setPosition (newpos);
-			ref->setTransform (newMatrix);
+			newpos.transform( transform, pos );
+			ref->setPosition( newpos );
+			ref->setTransform( newMatrix );
 		}
 		break;
 	
@@ -231,77 +254,72 @@
 		break;
 	}
 	
-	if (obj->color () == maincolor)
-		obj->setColor (parentcolor);
+	if( obj->color() == maincolor )
+		obj->setColor( parentcolor );
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-vector<LDObject*> LDSubfile::inlineContents (bool deep, bool cache) {
+vector<LDObject*> LDSubfile::inlineContents( bool deep, bool cache )
+{
 	vector<LDObject*> objs, objcache;
 	
 	// If we have this cached, just clone that
-	if (deep && fileInfo ()->cache ().size ()) {
-		for (LDObject* obj : fileInfo ()->cache ())
-			objs << obj->clone ();
-	} else {
-		if (!deep)
+	if( deep && fileInfo()->cache().size() )
+	{
+		for( LDObject * obj : fileInfo()->cache() )
+			objs << obj->clone();
+	}
+	else
+	{
+		if( !deep )
 			cache = false;
-		
-		for (LDObject* obj : *fileInfo ()) {
-			// Skip those without schemantic meaning
-			switch (obj->getType ()) {
-			case LDObject::Comment:
-			case LDObject::Empty:
-			case LDObject::Gibberish:
-			case LDObject::Unidentified:
-			case LDObject::Vertex:
+
+		for( LDObject * obj : *fileInfo() )
+		{
+			// Skip those without scemantic meaning
+			if( !obj->isScemantic() )
 				continue;
 			
-			case LDObject::BFC:
-				// Filter non-INVERTNEXT statements
-				if (static_cast<LDBFC*> (obj)->type != LDBFC::InvertNext)
-					continue;
-				break;
-			
-			default:
-				break;
-			}
-			
 			// Got another sub-file reference, inline it if we're deep-inlining. If not,
 			// just add it into the objects normally. Also, we only cache immediate
 			// subfiles and this is not one. Yay, recursion!
-			if (deep && obj->getType() == LDObject::Subfile) {
-				LDSubfile* ref = static_cast<LDSubfile*> (obj);
+			if( deep && obj->getType() == LDObject::Subfile )
+			{
+				LDSubfile* ref = static_cast<LDSubfile*>( obj );
 				
-				vector<LDObject*> otherobjs = ref->inlineContents (true, false);
+				vector<LDObject*> otherobjs = ref->inlineContents( true, false );
 				
-				for (LDObject* otherobj : otherobjs) {
+				for( LDObject * otherobj : otherobjs )
+				{
 					// Cache this object, if desired
-					if (cache)
-						objcache << otherobj->clone ();
+					if( cache )
+						objcache << otherobj->clone();
 					
 					objs << otherobj;
 				}
-			} else {
-				if (cache)
-					objcache << obj->clone ();
+			}
+			else
+			{
+				if( cache )
+					objcache << obj->clone();
 				
-				objs << obj->clone ();
+				objs << obj->clone();
 			}
 		}
 		
-		if (cache)
-			fileInfo ()->setCache (objcache);
+		if( cache )
+			fileInfo()->setCache( objcache );
 	}
 	
 	// Transform the objects
-	for (LDObject* obj : objs) {
+	for( LDObject * obj : objs )
+	{
 		// Set the parent now so we know what inlined this.
-		obj->setParent (this);
+		obj->setParent( this );
 		
-		transformObject (obj, transform (), position (), color ());
+		transformObject( obj, transform(), position(), color() );
 	}
 	
 	return objs;
@@ -310,9 +328,10 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-long LDObject::getIndex (LDOpenFile* file) const {
-	for (ulong i = 0; i < file->numObjs (); ++i)
-		if (file->obj (i) == this)
+long LDObject::getIndex( LDOpenFile* file ) const
+{
+	for( ulong i = 0; i < file->numObjs(); ++i )
+		if( file->obj( i ) == this )
 			return i;
 	
 	return -1;
@@ -321,40 +340,42 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void LDObject::moveObjects (vector<LDObject*> objs, const bool bUp) {
+void LDObject::moveObjects( vector<LDObject*> objs, const bool up )
+{
 	// If we move down, we need to iterate the array in reverse order.
-	const long start = bUp ? 0 : (objs.size() - 1);
-	const long end = bUp ? objs.size() : -1;
-	const long incr = bUp ? 1 : -1;
-	
+	const long start = up ? 0 : ( objs.size() - 1 );
+	const long end = up ? objs.size() : -1;
+	const long incr = up ? 1 : -1;
 	vector<LDObject*> objsToCompile;
 	
-	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 (g_curfile),
-			target = idx + (bUp ? -1 : 1);
+		const long idx = obj->getIndex( g_curfile ),
+				   target = idx + ( up ? -1 : 1 );
 		
-		if ((bUp == true and idx == 0) or
-			(bUp == false and idx == (long)(g_curfile->objs ().size() - 1)))
+		if(( up && idx == 0 ) || ( !up && idx == (long) ( g_curfile->objs().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 << g_curfile->obj (target);
+		objsToCompile << g_curfile->obj( target );
 		
-		obj->swap (g_curfile->obj (target));
+		obj->swap( g_curfile->obj( target ) );
 	}
 	
+	objsToCompile.makeUnique();
+	
 	// 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 )
@@ -368,34 +389,36 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-str LDObject::objectListContents (const vector<LDObject*>& objs) {
+str LDObject::objectListContents( const vector<LDObject*>& objs )
+{
 	bool firstDetails = true;
 	str text = "";
 	
-	if (objs.size() == 0)
+	if( objs.size() == 0 )
 		return "nothing"; // :)
 	
-	for (long i = 0; i < LDObject::NumTypes; ++i) {
-		LDObject::Type objType = (LDObject::Type) i;
+	for( long i = 0; i < LDObject::NumTypes; ++i )
+	{
+		LDObject::Type objType = ( LDObject::Type ) i;
 		ulong objCount = 0;
 		
-		for (LDObject* obj : objs)
-			if (obj->getType() == objType)
+		for( LDObject * obj : objs )
+			if( obj->getType() == objType )
 				objCount++;
 		
-		if (objCount == 0)
+		if( objCount == 0 )
 			continue;
 		
-		if (!firstDetails)
+		if( !firstDetails )
 			text += ", ";
 		
-		str noun = fmt ("%1%2", typeName( objType ), plural( objCount ));
+		str noun = fmt( "%1%2", typeName( objType ), plural( objCount ) );
 		
 		// Plural of "vertex" is "vertices". Stupid English.
-		if (objType == LDObject::Vertex && objCount != 1)
+		if( objType == LDObject::Vertex && objCount != 1 )
 			noun = "vertices";
 		
-		text += fmt  ("%1 %2", objCount, noun);
+		text += fmt( "%1 %2", objCount, noun );
 		firstDetails = false;
 	}
 	
@@ -403,128 +426,142 @@
 }
 
 // =============================================================================
-LDObject* LDObject::topLevelParent () {
-	if (!parent ())
+LDObject* LDObject::topLevelParent()
+{
+	if( !parent() )
 		return this;
 	
 	LDObject* it = this;
 	
-	while (it->parent ())
-		it = it->parent ();
+	while( it->parent() )
+		it = it->parent();
 	
 	return it;
 }
 
 // =============================================================================
-LDObject* LDObject::next () const {
-	long idx = getIndex (g_curfile);
-	assert (idx != -1);
+LDObject* LDObject::next() const
+{
+	long idx = getIndex( g_curfile );
+	assert( idx != -1 );
 	
-	if (idx == (long) g_curfile->numObjs () - 1)
+	if( idx == ( long ) g_curfile->numObjs() - 1 )
 		return null;
 	
-	return g_curfile->obj (idx + 1);
+	return g_curfile->obj( idx + 1 );
 }
 
 // =============================================================================
-LDObject* LDObject::prev () const {
-	long idx = getIndex (g_curfile);
-	assert (idx != -1);
+LDObject* LDObject::prev() const
+{
+	long idx = getIndex( g_curfile );
+	assert( idx != -1 );
 	
-	if (idx == 0)
+	if( idx == 0 )
 		return null;
 	
-	return g_curfile->obj (idx - 1);
+	return g_curfile->obj( idx - 1 );
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void LDObject::move (vertex vect) { (void) vect; }
-void LDEmpty::move (vertex vect) { (void) vect; }
-void LDBFC::move (vertex vect) { (void) vect; }
-void LDComment::move (vertex vect) { (void) vect; }
-void LDGibberish::move (vertex vect) { (void) vect; }
+void LDObject::move( vertex vect ) { (void) vect; }
+void LDEmpty::move( vertex vect ) { (void) vect; }
+void LDBFC::move( vertex vect ) { (void) vect; }
+void LDComment::move( vertex vect ) { (void) vect; }
+void LDGibberish::move( vertex vect ) { (void) vect; }
 
-void LDVertex::move (vertex vect) {
+void LDVertex::move( vertex vect )
+{
 	pos += vect;
 }
 
-void LDSubfile::move (vertex vect) {
-	setPosition (position () + vect);
+void LDSubfile::move( vertex vect )
+{
+	setPosition( position() + vect );
 }
 
-void LDLine::move (vertex vect) {
-	for (short i = 0; i < 2; ++i)
-		setVertex (i, getVertex (i) + vect);
+void LDLine::move( vertex vect )
+{
+	for( short i = 0; i < 2; ++i )
+		setVertex( i, getVertex( i ) + vect );
 }
 
-void LDTriangle::move (vertex vect) {
-	for (short i = 0; i < 3; ++i)
-		setVertex (i, getVertex (i) + vect);
+void LDTriangle::move( vertex vect )
+{
+	for( short i = 0; i < 3; ++i )
+		setVertex( i, getVertex( i ) + vect );
 }
 
-void LDQuad::move (vertex vect) {
-	for (short i = 0; i < 4; ++i)
-		setVertex (i, getVertex (i) + vect);
+void LDQuad::move( vertex vect )
+{
+	for( short i = 0; i < 4; ++i )
+		setVertex( i, getVertex( i ) + vect );
 }
 
-void LDCondLine::move (vertex vect) {
-	for (short i = 0; i < 4; ++i)
-		setVertex (i, getVertex (i) + vect);
+void LDCondLine::move( vertex vect )
+{
+	for( short i = 0; i < 4; ++i )
+		setVertex( i, getVertex( i ) + vect );
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 #define CHECK_FOR_OBJ(N) \
-	if (type == LDObject::N) \
+	if( type == LDObject::N ) \
 		return new LD##N;
-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 (Gibberish)
-	CHECK_FOR_OBJ (Vertex)
-	CHECK_FOR_OBJ (Overlay)
+
+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( Gibberish )
+	CHECK_FOR_OBJ( Vertex )
+	CHECK_FOR_OBJ( Overlay )
 	return null;
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void LDObject::invert () { }
-void LDBFC::invert () { }
-void LDEmpty::invert () { }
-void LDComment::invert () { }
-void LDGibberish::invert () { }
+void LDObject::invert() {}
+void LDBFC::invert() {}
+void LDEmpty::invert() {}
+void LDComment::invert() {}
+void LDGibberish::invert() {}
 
-void LDTriangle::invert () {
+void LDTriangle::invert()
+{
 	// 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;
 }
 
-void LDQuad::invert () {
+void LDQuad::invert()
+{
 	// 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 );
 }
 
-void LDSubfile::invert () {
+void LDSubfile::invert()
+{
 	// Subfiles are inverted when they're prefixed with
 	// a BFC INVERTNEXT statement. Thus we need to toggle this status.
 	// For flat primitives it's sufficient that the determinant is
@@ -533,7 +570,8 @@
 	
 	ulong idx = getIndex( g_curfile );
 	
-	if (idx > 0) {
+	if( idx > 0 )
+	{
 		LDBFC* bfc = dynamic_cast<LDBFC*>( prev() );
 		
 		if( bfc && bfc->type == LDBFC::InvertNext )
@@ -550,39 +588,44 @@
 	g_curfile->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);
+void LDLine::invert()
+{
+	invertLine( this );
 }
 
-void LDCondLine::invert () {
-	invertLine (this);
+void LDCondLine::invert()
+{
+	invertLine( this );
 }
 
-void LDVertex::invert () { }
+void LDVertex::invert() {}
 
 // =============================================================================
-LDLine* LDCondLine::demote () {
+LDLine* LDCondLine::demote()
+{
 	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 (color ());
+	repl->setColor( color() );
 	
-	replace (repl);
+	replace( repl );
 	return repl;
 }
 
-LDObject* LDObject::fromID (int id) {
-	for( LDObject* obj : g_LDObjects )
+LDObject* LDObject::fromID( int id )
+{
+	for( LDObject * obj : g_LDObjects )
 		if( obj->id() == id )
 			return obj;
 	
@@ -596,41 +639,66 @@
 		filename(), camera(), x(), y(), width(), height() );
 }
 
-void LDOverlay::move( vertex vect ) { Q_UNUSED( vect ) }
+void LDOverlay::move( vertex vect )
+{
+	Q_UNUSED( vect )
+}
+
 void LDOverlay::invert() {}
 
 // =============================================================================
-template<class T> void changeProperty (LDObject* obj, T* ptr, const T& val) {
+template<class T> void changeProperty( LDObject* obj, T* ptr, const T& val )
+{
 	long idx;
-	if ((idx = obj->getIndex (g_curfile)) != -1) {
-		str before = obj->raw ();
+	
+	if(( idx = obj->getIndex( g_curfile )) != -1 )
+	{
+		str before = obj->raw();
 		*ptr = val;
-		str after = obj->raw ();
-		
-		g_curfile->addToHistory (new EditHistory (idx, before, after));
-	} else
+		str after = obj->raw();
+
+		g_curfile->addToHistory( new EditHistory( idx, before, after ) );
+	}
+	else
 		*ptr = val;
 }
 
-READ_ACCESSOR (short, LDObject::color) { return m_color; }
-SET_ACCESSOR (short, LDObject::setColor) {
-	changeProperty (this, &m_color, val);
+READ_ACCESSOR( short, LDObject::color )
+{
+	return m_color;
 }
 
-const vertex& LDObject::getVertex (int i) const {
+SET_ACCESSOR( short, LDObject::setColor )
+{
+	changeProperty( this, &m_color, val );
+}
+
+const vertex& LDObject::getVertex( int i ) const
+{
 	return m_coords[i];
 }
 
-void LDObject::setVertex (int i, const vertex& vert) {
-	changeProperty (this, &m_coords[i], vert);
+void LDObject::setVertex( int i, const vertex& vert )
+{
+	changeProperty( this, &m_coords[i], vert );
+}
+
+READ_ACCESSOR( vertex, LDMatrixObject::position )
+{
+	return m_position;
 }
 
-READ_ACCESSOR (vertex, LDMatrixObject::position) { return m_position; }
-SET_ACCESSOR (vertex, LDMatrixObject::setPosition) {
-	changeProperty (linkPointer (), &m_position, val);
+SET_ACCESSOR( vertex, LDMatrixObject::setPosition )
+{
+	changeProperty( linkPointer(), &m_position, val );
 }
 
-READ_ACCESSOR (matrix, LDMatrixObject::transform) { return m_transform; }
-SET_ACCESSOR (matrix, LDMatrixObject::setTransform) {
-	changeProperty (linkPointer (), &m_transform, val);
+READ_ACCESSOR( matrix, LDMatrixObject::transform )
+{
+	return m_transform;
+}
+
+SET_ACCESSOR( matrix, LDMatrixObject::setTransform )
+{
+	changeProperty( linkPointer(), &m_transform, val );
 }
\ No newline at end of file

mercurial