more formatting

Sat, 13 Jul 2013 21:21:33 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 13 Jul 2013 21:21:33 +0300
changeset 378
bc3f40dcfa9e
parent 377
271d1da66b7e
child 379
f5f3faac60cd

more formatting

src/extprogs.cpp file | annotate | diff | comparison | revisions
src/file.cpp file | annotate | diff | comparison | revisions
src/gldraw.cpp file | annotate | diff | comparison | revisions
--- a/src/extprogs.cpp	Sat Jul 13 19:02:48 2013 +0300
+++ b/src/extprogs.cpp	Sat Jul 13 21:21:33 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/>.
  */
@@ -79,14 +79,14 @@
 
 // =============================================================================
 static bool checkProgPath (str path, const extprog prog) {
-	if (path.length () > 0)
+	if (path.length() > 0)
 		return true;
 	
 	const char* name = g_extProgNames[prog];
 	
-	critical (fmt ("Couldn't run %1 as no path has "
+	critical (fmt (QObject::tr ("Couldn't run %1 as no path has "
 		"been defined for it. Use the configuration dialog's External Programs "
-		"tab to define a path for %1.", name));
+		"tab to define a path for %1."), name));
 	return false;
 }
 
@@ -107,7 +107,7 @@
 		return "Unknown error";
 	
 	case QProcess::Timedout:
-		return fmt( "Timed out (30 seconds)" );
+		return fmt ("Timed out (30 seconds)");
 	}
 	
 	return "";
@@ -115,50 +115,53 @@
 
 // =============================================================================
 static bool mkTempFile (QTemporaryFile& tmp, str& fname) {
-	if (!tmp.open ())
+	if (!tmp.open())
 		return false;
 	
-	fname = tmp.fileName ();
-	tmp.close ();
+	fname = tmp.fileName();
+	tmp.close();
 	return true;
 }
 
 // =============================================================================
 void writeObjects (vector<LDObject*>& objects, File& f) {
 	for (LDObject* obj : objects) {
-		if (obj->getType () == LDObject::Subfile) {
+		if (obj->getType() == LDObject::Subfile) {
 			vector<LDObject*> objs = static_cast<LDSubfileObject*> (obj)->inlineContents (true, false);
 			
 			writeObjects (objs, f);
+			
 			for (LDObject* obj : objs)
 				delete obj;
 		} else
-			f.write (obj->raw () + "\r\n");
+			f.write (obj->raw() + "\r\n");
 	}
 }
 
 void writeObjects (vector<LDObject*>& objects, str fname) {
 	// Write the input file
 	File f (fname, File::Write);
+	
 	if (!f) {
 		critical (fmt ("Couldn't open temporary file %1 for writing.\n", fname));
 		return;
 	}
 	
 	writeObjects (objects, f);
-	f.close ();
+	f.close();
 }
 
 // =============================================================================
 void writeSelection (str fname) {
-	writeObjects (g_win->sel (), fname);
+	writeObjects (g_win->sel(), fname);
 }
 
 // =============================================================================
 void writeColorGroup (const short colnum, str fname) {
 	vector<LDObject*> objects;
-	for (LDObject*& obj : *g_curfile) {
-		if (obj->isColored () == false || obj->color () != colnum)
+	
+	for (LDObject* obj : *g_curfile) {
+		if (obj->isColored() == false || obj->color() != colnum)
 			continue;
 		
 		objects << obj;
@@ -167,22 +170,6 @@
 	writeObjects (objects, fname);
 }
 
-void waitForProcess( QProcess* proc ) {
-	proc->waitForFinished();
-	
-#if 0
-	int msecs = 30000;
-	int msectic = 10;
-	
-	for (int i = 0; i < msecs / msectic; ++i) {
-		if (proc->waitForFinished (msectic))
-			return;
-		
-		
-	}
-#endif // 0
-}
-
 // =============================================================================
 bool runUtilityProcess (extprog prog, str path, str argvstr) {
 	QTemporaryFile input, output;
@@ -199,7 +186,7 @@
 	print ("cmdline: %1 %2\n", path, argv.join (" "));
 	
 	// Temporary files for stdin and stdout
-	if( !mkTempFile( input, inputname ) || !mkTempFile( output, outputname ))
+	if (!mkTempFile (input, inputname) || !mkTempFile (output, outputname))
 		return false;
 	
 	QProcess proc;
@@ -215,15 +202,15 @@
 	stdinfp.write ("\n");
 	
 	// Wait while it runs
-	waitForProcess( &proc );
+	proc.waitForFinished();
 	
 #ifndef RELEASE
-	print ("%1", str (proc.readAllStandardOutput ()));
+	print ("%1", str (proc.readAllStandardOutput()));
 #endif // RELEASE
 	
 	str err = "";
 	
-	if ( proc.exitStatus() != QProcess::NormalExit )
+	if (proc.exitStatus() != QProcess::NormalExit)
 		err = processErrorString (proc);
 	
 	// Check the return code
@@ -246,6 +233,7 @@
 	
 	// Read the output file
 	File f (fname, File::Read);
+	
 	if (!f) {
 		critical (fmt ("Couldn't open temporary file %1 for reading.\n", fname));
 		return;
@@ -255,31 +243,32 @@
 	
 	// If we replace the objects, delete the selection now.
 	if (replace)
-		g_win->deleteSelection ();
+		g_win->deleteSelection();
 	
 	for (const short colnum : colorsToReplace)
 		g_win->deleteByColor (colnum);
 	
 	// Insert the new objects
-	g_win->sel ().clear ();
-	for (LDObject* obj : objs) {
-		if (!obj->isScemantic ()) {
+	g_win->sel().clear();
+	
+	for (LDObject * obj : objs) {
+		if (!obj->isScemantic()) {
 			delete obj;
 			continue;
 		}
 		
 		g_curfile->addObject (obj);
-		g_win->sel () << obj;
+		g_win->sel() << obj;
 	}
 	
-	g_win->fullRefresh ();
+	g_win->fullRefresh();
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 // Interface for Ytruder
-void runYtruder () {
+void runYtruder() {
 	setlocale (LC_ALL, "C");
 	
 	if (!checkProgPath (prog_ytruder, Ytruder))
@@ -287,9 +276,9 @@
 	
 	QDialog* dlg = new QDialog;
 	Ui::YtruderUI ui;
-	ui.setupUi( dlg );
+	ui.setupUi (dlg);
 	
-	if (!dlg->exec ())
+	if (!dlg->exec())
 		return;
 	
 	// Read the user's choices
@@ -313,7 +302,7 @@
 		return;
 	
 	// Compose the command-line arguments
-	str argv = join ({
+	str argv = join ( {
 		(axis == X) ? "-x" : (axis == Y) ? "-y" : "-z",
 		(mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r",
 		depth,
@@ -335,7 +324,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 // Rectifier interface
-void runRectifier () {
+void runRectifier() {
 	setlocale (LC_ALL, "C");
 	
 	if (!checkProgPath (prog_rectifier, Rectifier))
@@ -345,7 +334,7 @@
 	Ui::RectifierUI ui;
 	ui.setupUi (dlg);
 	
-	if (!dlg->exec ())
+	if (!dlg->exec())
 		return;
 	
 	QTemporaryFile indat, outdat;
@@ -356,13 +345,13 @@
 		return;
 	
 	// Compose arguments
-	str argv = join ({
-		(!ui.cb_condense->isChecked ()) ? "-q" : "",
-		(!ui.cb_subst->isChecked ()) ? "-r" : "",
-		(ui.cb_condlineCheck->isChecked ()) ? "-a" : "",
-		(ui.cb_colorize->isChecked ()) ? "-c" : "",
+	str argv = join ( {
+		(!ui.cb_condense->isChecked()) ? "-q" : "",
+		(!ui.cb_subst->isChecked()) ? "-r" : "",
+		(ui.cb_condlineCheck->isChecked()) ? "-a" : "",
+		(ui.cb_colorize->isChecked()) ? "-c" : "",
 		"-t",
-		ui.dsb_coplthres->value (),
+		ui.dsb_coplthres->value(),
 		inDATName,
 		outDATName
 	});
@@ -377,7 +366,7 @@
 
 LabeledWidget<QComboBox>* buildColorSelector (const char* label) {
 	LabeledWidget<QComboBox>* widget = new LabeledWidget<QComboBox> (label, new QComboBox);
-	makeColorSelector (widget->w ());
+	makeColorSelector (widget->w());
 	return widget;
 }
 
@@ -385,7 +374,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 // Intersector interface
-void runIntersector () {
+void runIntersector() {
 	setlocale (LC_ALL, "C");
 	
 	if (!checkProgPath (prog_intersector, Intersector))
@@ -393,24 +382,23 @@
 	
 	QDialog* dlg = new QDialog;
 	Ui::IntersectorUI ui;
-	ui.setupUi( dlg );
+	ui.setupUi (dlg);
 	
-	makeColorSelector( ui.cmb_incol );
-	makeColorSelector( ui.cmb_cutcol );
-	ui.cb_repeat->setWhatsThis( "If this is set, " APPNAME " runs Intersector a second time with inverse files to cut the "
-		" cutter group with the input group. Both groups are cut by the intersection." );
-	ui.cb_edges->setWhatsThis( "Makes " APPNAME " try run Isecalc to create edgelines for the intersection." );
+	makeColorSelector (ui.cmb_incol);
+	makeColorSelector (ui.cmb_cutcol);
+	ui.cb_repeat->setWhatsThis ("If this is set, " APPNAME " runs Intersector a second time with inverse files to cut the "
+		" cutter group with the input group. Both groups are cut by the intersection.");
+	ui.cb_edges->setWhatsThis ("Makes " APPNAME " try run Isecalc to create edgelines for the intersection.");
 	
 	short inCol, cutCol;
-	const bool repeatInverse = ui.cb_repeat->isChecked ();
+	const bool repeatInverse = ui.cb_repeat->isChecked();
 	
-	for( ;; )
-	{
-		if (!dlg->exec ())
+	for (;;) {
+		if (!dlg->exec())
 			return;
 		
-		inCol = ui.cmb_incol->itemData (ui.cmb_incol->currentIndex ()).toInt ();
-		cutCol =  ui.cmb_cutcol->itemData (ui.cmb_cutcol->currentIndex ()).toInt ();
+		inCol = ui.cmb_incol->itemData (ui.cmb_incol->currentIndex()).toInt();
+		cutCol =  ui.cmb_cutcol->itemData (ui.cmb_cutcol->currentIndex()).toInt();
 		
 		if (inCol == cutCol) {
 			critical ("Cannot use the same color group for both input and cutter!");
@@ -430,17 +418,16 @@
 	str inDATName, cutDATName, outDATName, outDAT2Name, edgesDATName;
 	
 	if (!mkTempFile (indat, inDATName) || !mkTempFile (cutdat, cutDATName) ||
-		!mkTempFile (outdat, outDATName) || !mkTempFile (outdat2, outDAT2Name) ||
-		!mkTempFile (edgesdat, edgesDATName))
-	{
+			!mkTempFile (outdat, outDATName) || !mkTempFile (outdat2, outDAT2Name) ||
+			!mkTempFile (edgesdat, edgesDATName)) {
 		return;
 	}
 	
-	str parms = join ({
-		(ui.cb_colorize->isChecked ()) ? "-c" : "",
-		(ui.cb_nocondense->isChecked ()) ? "-t" : "",
+	str parms = join ( {
+		(ui.cb_colorize->isChecked()) ? "-c" : "",
+		(ui.cb_nocondense->isChecked()) ? "-t" : "",
 		"-s",
-		ui.dsb_prescale->value ()
+		ui.dsb_prescale->value()
 	});
 	
 	str argv_normal = join ({
@@ -468,7 +455,7 @@
 	if (repeatInverse && runUtilityProcess (Intersector, prog_intersector, argv_inverse))
 		insertOutput (outDAT2Name, false, {cutCol});
 	
-	if (ui.cb_edges->isChecked () && runUtilityProcess (Isecalc, prog_isecalc,
+	if (ui.cb_edges->isChecked() && runUtilityProcess (Isecalc, prog_isecalc,
 		join ({inDATName, cutDATName, edgesDATName})))
 	{
 		insertOutput (edgesDATName, false, {});
@@ -478,7 +465,7 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void runCoverer () {
+void runCoverer() {
 	setlocale (LC_ALL, "C");
 	
 	if (!checkProgPath (prog_coverer, Coverer))
@@ -486,23 +473,23 @@
 	
 	QDialog* dlg = new QDialog;
 	Ui::CovererUI ui;
-	ui.setupUi( dlg );
-	makeColorSelector( ui.cmb_col1 );
-	makeColorSelector( ui.cmb_col2 );
+	ui.setupUi (dlg);
+	makeColorSelector (ui.cmb_col1);
+	makeColorSelector (ui.cmb_col2);
 	
 	short in1Col, in2Col;
+	
 	for (;;) {
-		if (!dlg->exec ())
+		if (!dlg->exec())
 			return;
 		
-		in1Col = ui.cmb_col1->itemData (ui.cmb_col1->currentIndex ()).toInt ();
-		in2Col = ui.cmb_col2->itemData (ui.cmb_col2->currentIndex ()).toInt ();
+		in1Col = ui.cmb_col1->itemData (ui.cmb_col1->currentIndex()).toInt();
+		in2Col = ui.cmb_col2->itemData (ui.cmb_col2->currentIndex()).toInt();
 		
 		if (in1Col == in2Col) {
 			critical ("Cannot use the same color group for both input and cutter!");
 			continue;
 		}
-		
 		break;
 	}
 	
@@ -512,11 +499,11 @@
 	if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName))
 		return;
 	
-	str argv = join ({
-		(ui.cb_oldsweep->isChecked () ? "-s" : ""),
-		(ui.cb_reverse->isChecked () ? "-r" : ""),
-		(ui.dsb_segsplit->value () != 0 ? fmt ("-l %1", ui.dsb_segsplit->value ()) : ""),
-		(ui.sb_bias->value () != 0 ? fmt ("-s %1", ui.sb_bias->value ()) : ""),
+	str argv = join ( {
+		(ui.cb_oldsweep->isChecked() ? "-s" : ""),
+		(ui.cb_reverse->isChecked() ? "-r" : ""),
+		(ui.dsb_segsplit->value() != 0 ? fmt ("-l %1", ui.dsb_segsplit->value()) : ""),
+		(ui.sb_bias->value() != 0 ? fmt ("-s %1", ui.sb_bias->value()) : ""),
 		in1DATName,
 		in2DATName,
 		outDATName
@@ -534,7 +521,7 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void runIsecalc () {
+void runIsecalc() {
 	setlocale (LC_ALL, "C");
 	
 	if (!checkProgPath (prog_isecalc, Isecalc))
@@ -542,21 +529,20 @@
 	
 	Ui::IsecalcUI ui;
 	QDialog* dlg = new QDialog;
-	ui.setupUi( dlg );
+	ui.setupUi (dlg);
 	
-	makeColorSelector( ui.cmb_col1 );
-	makeColorSelector( ui.cmb_col2 );
+	makeColorSelector (ui.cmb_col1);
+	makeColorSelector (ui.cmb_col2);
 	
 	short in1Col, in2Col;
 	
 	// Run the dialog and validate input
-	for( ;; )
-	{
-		if (!dlg->exec ())
+	for (;;) {
+		if (!dlg->exec())
 			return;
 		
-		in1Col = ui.cmb_col1->itemData (ui.cmb_col1->currentIndex ()).toInt (),
-			in2Col = ui.cmb_col1->itemData (ui.cmb_col2->currentIndex ()).toInt ();
+		in1Col = ui.cmb_col1->itemData (ui.cmb_col1->currentIndex()).toInt(),
+		in2Col = ui.cmb_col1->itemData (ui.cmb_col2->currentIndex()).toInt();
 		
 		if (in1Col == in2Col) {
 			critical ("Cannot use the same color group for both input and cutter!");
@@ -572,7 +558,7 @@
 	if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName))
 		return;
 	
-	str argv = join ({
+	str argv = join ( {
 		in1DATName,
 		in2DATName,
 		outDATName
@@ -587,48 +573,47 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-MAKE_ACTION( edger2, "Edger 2", "edger2", "Compute edgelines", 0 )
-{
+MAKE_ACTION (edger2, "Edger 2", "edger2", "Compute edgelines", 0) {
 	setlocale (LC_ALL, "C");
 	
-	if( !checkProgPath( prog_edger2, Edger2 ))
+	if (!checkProgPath (prog_edger2, Edger2))
 		return;
 	
 	QDialog* dlg = new QDialog;
 	Ui::Edger2Dialog ui;
-	ui.setupUi( dlg );
+	ui.setupUi (dlg);
 	
-	if( !dlg->exec() )
+	if (!dlg->exec())
 		return;
 	
 	QTemporaryFile in, out;
 	str inName, outName;
 	
-	if( !mkTempFile( in, inName ) || !mkTempFile( out, outName ))
+	if (!mkTempFile (in, inName) || !mkTempFile (out, outName))
 		return;
 	
 	int unmatched = ui.unmatched->currentIndex();
 	
-	str argv = join({
-		fmt( "-p %1", ui.precision->value() ),
-		fmt( "-af %1", ui.flatAngle->value() ),
-		fmt( "-ac %1", ui.condAngle->value() ),
-		fmt( "-ae %1", ui.edgeAngle->value() ),
+	str argv = join ( {
+		fmt ("-p %1", ui.precision->value()),
+		fmt ("-af %1", ui.flatAngle->value()),
+		fmt ("-ac %1", ui.condAngle->value()),
+		fmt ("-ae %1", ui.edgeAngle->value()),
 		ui.delLines->isChecked()     ? "-de" : "",
 		ui.delCondLines->isChecked() ? "-dc" : "",
 		ui.colored->isChecked()      ? "-c" : "",
 		ui.bfc->isChecked()          ? "-b" : "",
 		ui.convex->isChecked()       ? "-cx" : "",
 		ui.concave->isChecked()      ? "-cv" : "",
-		unmatched == 0 ? "-u+" : ( unmatched == 2 ? "-u-" : "" ),
+		unmatched == 0 ? "-u+" : (unmatched == 2 ? "-u-" : ""),
 		inName,
 		outName,
 	});
 	
-	writeSelection( inName );
+	writeSelection (inName);
 	
-	if( !runUtilityProcess( Edger2, prog_edger2, argv ))
+	if (!runUtilityProcess (Edger2, prog_edger2, argv))
 		return;
 	
-	insertOutput( outName, true, {} );
+	insertOutput (outName, true, {});
 }
\ No newline at end of file
--- a/src/file.cpp	Sat Jul 13 19:02:48 2013 +0300
+++ b/src/file.cpp	Sat Jul 13 21:21:33 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/>.
  */
@@ -32,16 +32,15 @@
 #include "dialogs.h"
 #include "gldraw.h"
 
-cfg( str, io_ldpath, "" );
-cfg( str, io_recentfiles, "" );
+cfg (str, io_ldpath, "");
+cfg (str, io_recentfiles, "");
 
 static bool g_loadingMainFile = false;
 static const int g_MaxRecentFiles = 5;
 static bool g_aborted = false;
 
 // =============================================================================
-namespace LDPaths
-{
+namespace LDPaths {
 	static str pathError;
 	
 	struct {
@@ -50,35 +49,35 @@
 	} pathInfo;
 	
 	void initPaths() {
-		if( !tryConfigure( io_ldpath )) {
+		if (!tryConfigure (io_ldpath)) {
 			LDrawPathDialog dlg (false);
 			
-			if( !dlg.exec () )
-				exit( 0 );
+			if (!dlg.exec ())
+				exit (0);
 			
 			io_ldpath = dlg.filename();
 		}
 	}
 	
-	bool tryConfigure( str path ) {
+	bool tryConfigure (str path) {
 		QDir dir;
 		
-		if( !dir.cd( path )) {
+		if (!dir.cd (path)) {
 			pathError = "Directory does not exist.";
 			return false;
 		}
 		
 		QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
-		QStringList contents = dir.entryList( mustHave );
+		QStringList contents = dir.entryList (mustHave);
 		
-		if( contents.size() != mustHave.size() ) {
+		if (contents.size() != mustHave.size()) {
 			pathError = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/.";
 			return false;
 		}
 		
-		pathInfo.partsPath = fmt( "%1" DIRSLASH "parts", path );
-		pathInfo.LDConfigPath = fmt( "%1" DIRSLASH "LDConfig.ldr", path );
-		pathInfo.primsPath = fmt( "%1" DIRSLASH "p", path );
+		pathInfo.partsPath = fmt ("%1" DIRSLASH "parts", path);
+		pathInfo.LDConfigPath = fmt ("%1" DIRSLASH "LDConfig.ldr", path);
+		pathInfo.primsPath = fmt ("%1" DIRSLASH "p", path);
 		
 		return true;
 	}
@@ -91,44 +90,41 @@
 }
 
 // =============================================================================
-LDOpenFile::LDOpenFile()
-{
-	setImplicit( true );
-	setSavePos( -1 );
-	m_history.setFile( this );
+LDOpenFile::LDOpenFile() {
+	setImplicit (true);
+	setSavePos (-1);
+	m_history.setFile (this);
 }
 
 // =============================================================================
-LDOpenFile::~LDOpenFile()
-{
+LDOpenFile::~LDOpenFile() {
 	// Clear everything from the model
-	for( LDObject* obj : m_objs )
+	for (LDObject* obj : m_objs)
 		delete obj;
 	
 	// Clear the cache as well
-	for( LDObject* obj : m_cache )
+	for (LDObject* obj : m_cache)
 		delete obj;
 }
 
 // =============================================================================
-LDOpenFile* findLoadedFile( str name )
-{
-	for( LDOpenFile* file : g_loadedFiles )
-		if( file->name () == name )
+LDOpenFile* findLoadedFile (str name) {
+	for (LDOpenFile* file : g_loadedFiles)
+		if (file->name () == name)
 			return file;
 	
 	return null;
 }
 
 // =============================================================================
-str dirname( str path ) {
-	long lastpos = path.lastIndexOf( DIRSLASH );
+str dirname (str path) {
+	long lastpos = path.lastIndexOf (DIRSLASH);
 	
-	if( lastpos > 0 )
-		return path.left( lastpos );
+	if (lastpos > 0)
+		return path.left (lastpos);
 	
 #ifndef _WIN32
-	if( path[0] == DIRSLASH_CHAR )
+	if (path[0] == DIRSLASH_CHAR)
 		return DIRSLASH;
 #endif // _WIN32
 	
@@ -137,33 +133,35 @@
 
 // =============================================================================
 str basename (str path) {
-	long lastpos = path.lastIndexOf( DIRSLASH );
+	long lastpos = path.lastIndexOf (DIRSLASH);
 	
-	if( lastpos != -1 )
-		return path.mid( lastpos + 1 );
+	if (lastpos != -1)
+		return path.mid (lastpos + 1);
 	
 	return path;
 }
 
 // =============================================================================
 File* openLDrawFile (str relpath, bool subdirs) {
-	print( "%1: Try to open %2\n", __func__, relpath );
+	print ("%1: Try to open %2\n", __func__, relpath);
 	File* f = new File;
 	str fullPath;
 	
 	// LDraw models use Windows-style path separators. If we're not on Windows,
 	// replace the path separator now before opening any files.
 #ifndef WIN32
-	relpath.replace( "\\", "/" );
+	relpath.replace ("\\", "/");
 #endif // WIN32
 	
-	if( g_curfile ) {
+	if (g_curfile) {
 		// First, try find the file in the current model's file path. We want a file
 		// in the immediate vicinity of the current model to override stock LDraw stuff.
 		str partpath = fmt ("%1" DIRSLASH "%2", dirname (g_curfile->name ()), relpath);
 		
 		if (f->open (partpath, File::Read)) {
-			return f; }}
+			return f;
+		}
+	}
 	
 	if (f->open (relpath, File::Read))
 		return f;
@@ -171,20 +169,21 @@
 	// Try with just the LDraw path first
 	fullPath = fmt ("%1" DIRSLASH "%2", io_ldpath, relpath);
 	
-	if( f->open( fullPath, File::Read ))
+	if (f->open (fullPath, File::Read))
 		return f;
 	
-	if( subdirs ) {
+	if (subdirs) {
 		// Look in sub-directories: parts and p
-		for( auto subdir : initlist<const str>({ "parts", "p" })) {
-			fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3",
-				io_ldpath, subdir, relpath);
+		for (auto subdir : initlist<const str> ({ "parts", "p" })) {
+			fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", io_ldpath, subdir, relpath);
 			
 			if (f->open (fullPath, File::Read))
-				return f; }}
+				return f;
+		}
+	}
 	
 	// Did not find the file.
-	print( "could not find %1\n", relpath );
+	print ("could not find %1\n", relpath);
 	delete f;
 	return null;
 }
@@ -193,11 +192,11 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void FileLoader::start() {
-	setDone( false );
-	setProgress( 0 );
-	setAborted( false );
+	setDone (false);
+	setProgress (0);
+	setAborted (false);
 	
-	if( concurrent() ) {
+	if (concurrent()) {
 		g_aborted = false;
 		
 		// Show a progress dialog if we're loading the main file here and move
@@ -205,71 +204,76 @@
 		// operation and if we don't respond quickly enough, the program can be
 		// deemed inresponsive.. which is a bad thing.
 		dlg = new OpenProgressDialog (g_win);
-		dlg->setNumLines( lines().size() );
-		dlg->setModal( true );
+		dlg->setNumLines (lines().size());
+		dlg->setModal (true);
 		dlg->show();
 		
 		// Connect the loader in so we can show updates
-		connect( this, SIGNAL( workDone() ), dlg, SLOT( accept() ));
-		connect( dlg, SIGNAL( rejected() ), this, SLOT( abort() ));
+		connect (this, SIGNAL (workDone()), dlg, SLOT (accept()));
+		connect (dlg, SIGNAL (rejected()), this, SLOT (abort()));
 	} else
 		dlg = null;
 	
-	work( 0 );
+	work (0);
 }
 
-void FileLoader::work( ulong i ) {
-	if( aborted() ) {
+void FileLoader::work (ulong i) {
+	if (aborted()) {
 		// We were flagged for abortion, so abort.
-		for( LDObject* obj : m_objs )
+		for (LDObject* obj : m_objs)
 			delete obj;
 		
 		m_objs.clear();
-		setDone( true );
+		setDone (true);
 		return;
 	}
 	
 	ulong max = i + 300;
-	for( ; i < max && i < lines().size(); ++i ) {
-		str line = lines()[i];
+	
+	for (; i < max && i < lines().size(); ++i) {
+		str line = lines() [i];
 		
 		// Trim the trailing newline
 		qchar c;
-		while(( c = line[line.length () - 1] ) == '\n' || c == '\r' )
-			line.chop( 1 );
 		
-		LDObject* obj = parseLine( line );
+		while ((c = line[line.length () - 1]) == '\n' || c == '\r')
+			line.chop (1);
+		
+		LDObject* obj = parseLine (line);
 		
 		// Check for parse errors and warn about tthem
-		if( obj->getType () == LDObject::Error ) {
-			log( "Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDErrorObject*> (obj)->reason );
+		if (obj->getType () == LDObject::Error) {
+			log ("Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDErrorObject*> (obj)->reason);
 			
-			if( m_warningsPointer ) {
-				( *m_warningsPointer )++; }}
+			if (m_warningsPointer) {
+				(*m_warningsPointer) ++;
+			}
+		}
 		
 		m_objs << obj;
-		setProgress( i );
+		setProgress (i);
 		
-		if( concurrent() )
-			dlg->updateProgress( i );
+		if (concurrent())
+			dlg->updateProgress (i);
 	}
 	
-	if( i >= lines().size() - 1 ) {
+	if (i >= lines().size() - 1) {
 		emit workDone();
-		setDone( true ); }
+		setDone (true);
+	}
 	
-	if( !done() ) {
-		if( concurrent() )
-			QMetaObject::invokeMethod( this, "work", Qt::QueuedConnection, Q_ARG( ulong, i + 1 ));
+	if (!done()) {
+		if (concurrent())
+			QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection, Q_ARG (ulong, i + 1));
 		else
-			work( i + 1 );
+			work (i + 1);
 	}
 }
 
 void FileLoader::abort() {
-	setAborted( true );
+	setAborted (true);
 	
-	if( concurrent() )
+	if (concurrent())
 		g_aborted = true;
 }
 
@@ -280,25 +284,26 @@
 	vector<str> lines;
 	vector<LDObject*> objs;
 	
-	if( numWarnings )
+	if (numWarnings)
 		*numWarnings = 0;
 	
 	// Calculate the amount of lines
-	for( str line : *f )
+	for (str line : *f)
 		lines << line;
+	
 	f->rewind();
 	
 	FileLoader* loader = new FileLoader;
-	loader->setWarningsPointer( numWarnings );
-	loader->setLines( lines );
-	loader->setConcurrent( g_loadingMainFile );
+	loader->setWarningsPointer (numWarnings);
+	loader->setLines (lines);
+	loader->setConcurrent (g_loadingMainFile);
 	loader->start();
 	
-	while( loader->done() == false )
+	while (loader->done() == false)
 		qApp->processEvents();
 	
 	// If we wanted the success value, supply that now
-	if( ok )
+	if (ok)
 		*ok = !loader->aborted();
 	
 	objs = loader->objs();
@@ -308,59 +313,56 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-LDOpenFile* openDATFile( str path, bool search )
-{
+LDOpenFile* openDATFile (str path, bool search) {
 	// Convert the file name to lowercase since some parts contain uppercase
 	// file names. I'll assume here that the library will always use lowercase
 	// file names for the actual parts..
 	File* f;
-	if( search )
+	
+	if (search)
 		f = openLDrawFile (path.toLower (), true);
 	else {
-		f = new File( path, File::Read );
+		f = new File (path, File::Read);
 		
-		if( !*f ) {
+		if (!*f) {
 			delete f;
-			return null; }}
+			return null;
+		}
+	}
 	
-	if( !f )
+	if (!f)
 		return null;
 	
 	LDOpenFile* oldLoad = g_curfile;
 	LDOpenFile* load = new LDOpenFile;
-	load->setName( path );
+	load->setName (path);
 	
-	if( g_loadingMainFile )
-	{
+	if (g_loadingMainFile) {
 		g_curfile = load;
-		g_win->R()->setFile( load );
+		g_win->R()->setFile (load);
 	}
 	
 	ulong numWarnings;
 	bool ok;
-	vector<LDObject*> objs = loadFileContents( f, &numWarnings, &ok );
+	vector<LDObject*> objs = loadFileContents (f, &numWarnings, &ok);
 	
-	if( !ok )
-	{
-		if( g_loadingMainFile )
-		{
+	if (!ok) {
+		if (g_loadingMainFile) {
 			g_curfile = oldLoad;
-			g_win->R()->setFile( oldLoad );
+			g_win->R()->setFile (oldLoad);
 		}
 		
 		return null;
 	}
 	
-	for( LDObject* obj : objs )
-		load->addObject( obj );
+	for (LDObject* obj : objs)
+		load->addObject (obj);
 	
 	delete f;
 	g_loadedFiles << load;
 	
-	/*
-	logf ("File %s parsed successfully (%lu warning%s).\n",
-		qchars (path), numWarnings, plural (numWarnings));
-	*/
+	if (g_loadingMainFile)
+		log (QObject::tr ("File %1 parsed successfully (%2 warnings)."), path, numWarnings);
 	
 	return load;
 }
@@ -368,43 +370,41 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-bool LDOpenFile::safeToClose()
-{
+bool LDOpenFile::safeToClose() {
 	typedef QMessageBox msgbox;
-	setlocale( LC_ALL, "C" );
+	setlocale (LC_ALL, "C");
 	
 	// If we have unsaved changes, warn and give the option of saving.
-	if( !implicit() && history().pos() != savePos() )
-	{
-		str message = fmt( "There are unsaved changes to %1. Should it be saved?",
-			(name().length() > 0) ? name() : "<anonymous>");
-		switch( msgbox::question( g_win, "Unsaved Changes", message,
-			( msgbox::Yes | msgbox::No | msgbox::Cancel ), msgbox::Cancel ))
-		{
+	if (!implicit() && history().pos() != savePos()) {
+		str message = fmt ("There are unsaved changes to %1. Should it be saved?",
+						   (name().length() > 0) ? name() : "<anonymous>");
+		
+		int button = msgbox::question (g_win, "Unsaved Changes", message,
+			(msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel);
+		
+		switch (button) {
 		case msgbox::Yes:
 			// If we don't have a file path yet, we have to ask the user for one.
-			if( name().length() == 0 )
-			{
-				str newpath = QFileDialog::getSaveFileName( g_win, "Save As",
-					g_curfile->name(), "LDraw files (*.dat *.ldr)" );
+			if (name().length() == 0) {
+				str newpath = QFileDialog::getSaveFileName (g_win, "Save As",
+							  g_curfile->name(), "LDraw files (*.dat *.ldr)");
 				
-				if( newpath.length() == 0 )
+				if (newpath.length() == 0)
 					return false;
 				
-				setName( newpath );
+				setName (newpath);
 			}
 			
-			if( !save () ) {
-				message = fmt( QObject::tr( "Failed to save %1: %2\nDo you still want to close?" ),
-					name(), strerror( errno ));
+			if (!save ()) {
+				message = fmt (QObject::tr ("Failed to save %1: %2\nDo you still want to close?"),
+					name(), strerror (errno));
 				
-				if( QMessageBox::critical( g_win, "Save Failure", message,
-					( QMessageBox::Yes | QMessageBox::No ), QMessageBox::No ) == QMessageBox::No)
+				if (msgbox::critical (g_win, "Save Failure", message,
+					(msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No)
 				{
 					return false;
 				}
 			}
-			
 			break;
 		
 		case msgbox::Cancel:
@@ -421,13 +421,12 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void closeAll()
-{
-	if( !g_loadedFiles.size() )
+void closeAll() {
+	if (!g_loadedFiles.size())
 		return;
 	
 	// Remove all loaded files and the objects they contain
-	for( LDOpenFile* file : g_loadedFiles )
+	for (LDOpenFile* file : g_loadedFiles)
 		delete file;
 	
 	// Clear the array
@@ -441,19 +440,18 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void newFile ()
-{
+void newFile () {
 	closeAll();
 	
 	// Create a new anonymous file and set it to our current
 	LDOpenFile* f = new LDOpenFile;
-	f->setName( "" );
-	f->setImplicit( false );
+	f->setName ("");
+	f->setImplicit (false);
 	g_loadedFiles << f;
 	g_curfile = f;
 	
 	g_BBox.reset();
-	g_win->R()->setFile( f );
+	g_win->R()->setFile (f);
 	g_win->fullRefresh();
 	g_win->updateTitle();
 	f->history().updateActions();
@@ -462,31 +460,28 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void addRecentFile( str path )
-{
-	QStringList rfiles = io_recentfiles.value.split( '@' );
-	
-	int idx = rfiles.indexOf( path );
+void addRecentFile (str path) {
+	QStringList rfiles = io_recentfiles.value.split ('@');
+	int idx = rfiles.indexOf (path);
 	
 	// If this file already is in the list, pop it out.
-	if( idx != -1 )
-	{
-		if( rfiles.size () == 1 )
+	if (idx != -1) {
+		if (rfiles.size () == 1)
 			return; // only recent file - abort and do nothing
 		
 		// Pop it out.
-		rfiles.removeAt( idx );
+		rfiles.removeAt (idx);
 	}
 	
 	// If there's too many recent files, drop one out.
-	while( rfiles.size() > ( g_MaxRecentFiles - 1 ))
-		rfiles.removeAt( 0 );
+	while (rfiles.size() > (g_MaxRecentFiles - 1))
+		rfiles.removeAt (0);
 	
 	// Add the file
-	rfiles.push_back( path );
+	rfiles << path;
 	
 	// Rebuild the config string
-	io_recentfiles = rfiles.join( "@" );
+	io_recentfiles = rfiles.join ("@");
 	
 	config::save();
 	g_win->updateRecentFilesMenu();
@@ -496,31 +491,28 @@
 // -----------------------------------------------------------------------------
 // Open an LDraw file and set it as the main model
 // =============================================================================
-void openMainFile( str path )
-{
+void openMainFile (str path) {
 	g_loadingMainFile = true;
 	closeAll();
 	
-	LDOpenFile* file = openDATFile( path, false );
+	LDOpenFile* file = openDATFile (path, false);
 	
-	if (!file)
-	{
+	if (!file) {
 		// Loading failed, thus drop down to a new file since we
 		// closed everything prior.
 		newFile ();
 		
-		if( !g_aborted )
-		{
+		if (!g_aborted) {
 			// Tell the user loading failed.
-			setlocale( LC_ALL, "C" );
-			critical( fmt( QObject::tr( "Failed to open %1: %2" ), path, strerror( errno )));
+			setlocale (LC_ALL, "C");
+			critical (fmt (QObject::tr ("Failed to open %1: %2"), path, strerror (errno)));
 		}
 		
 		g_loadingMainFile = false;
 		return;
 	}
 	
-	file->setImplicit( false );
+	file->setImplicit (false);
 	g_curfile = file;
 	
 	// Recalculate the bounding box
@@ -529,60 +521,59 @@
 	// Rebuild the object tree view now.
 	g_win->fullRefresh();
 	g_win->updateTitle();
-	g_win->R()->setFile( file );
+	g_win->R()->setFile (file);
 	g_win->R()->resetAngles();
 	
 	// Add it to the recent files list.
-	addRecentFile( path );
+	addRecentFile (path);
 	g_loadingMainFile = false;
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-bool LDOpenFile::save( str savepath )
-{
-	if( !savepath.length() )
+bool LDOpenFile::save (str savepath) {
+	if (!savepath.length())
 		savepath = name();
 	
-	File f( savepath, File::Write );
+	File f (savepath, File::Write);
 	
-	if( !f )
+	if (!f)
 		return false;
 	
 	// If the second object in the list holds the file name, update that now.
 	// Only do this if the file is explicitly open. If it's saved into a directory
 	// called "s" or "48", prepend that into the name.
 	LDCommentObject* fpathComment = null;
-	LDObject* first = object( 1 );
-	if( !implicit() && first != null && first->getType() == LDObject::Comment )
-	{
-		fpathComment = static_cast<LDCommentObject*>( first );
+	LDObject* first = object (1);
+	
+	if (!implicit() && first != null && first->getType() == LDObject::Comment) {
+		fpathComment = static_cast<LDCommentObject*> (first);
 		
-		if( fpathComment->text.left( 6 ) == "Name: " ) {
+		if (fpathComment->text.left (6) == "Name: ") {
 			str newname;
-			str dir = basename( dirname( savepath ));
+			str dir = basename (dirname (savepath));
 			
-			if( dir == "s" || dir == "48" )
+			if (dir == "s" || dir == "48")
 				newname = dir + "\\";
 			
-			newname += basename( savepath );
-			fpathComment->text = fmt( "Name: %1", newname );
+			newname += basename (savepath);
+			fpathComment->text = fmt ("Name: %1", newname);
 			g_win->buildObjList();
 		}
 	}
 	
 	// File is open, now save the model to it. Note that LDraw requires files to
 	// have DOS line endings, so we terminate the lines with \r\n.
-	for( LDObject* obj : objs() )
-		f.write( obj->raw () + "\r\n" );
+	for (LDObject* obj : objs())
+		f.write (obj->raw () + "\r\n");
 	
 	// File is saved, now clean up.
 	f.close();
 	
 	// We have successfully saved, update the save position now.
-	setSavePos( history().pos() );
-	setName( savepath );
+	setSavePos (history().pos());
+	setName (savepath);
 	
 	g_win->updateTitle();
 	return true;
@@ -599,13 +590,13 @@
 	for (ushort i = MIN; i <= MAX; ++i) \
 		if (!isNumber (tokens[i])) \
 			return new LDErrorObject (line, fmt ("Token #%1 was `%2`, expected a number", \
-				(i + 1), tokens[i]));
+												 (i + 1), tokens[i]));
 
-static vertex parseVertex( QStringList& s, const ushort n )
-{
+static vertex parseVertex (QStringList& s, const ushort n) {
 	vertex v;
-	for( const Axis ax : g_Axes )
-		v[ax] = atof( s[n + ax] );
+	
+	for (const Axis ax : g_Axes)
+		v[ax] = atof (s[n + ax]);
 	
 	return v;
 }
@@ -616,153 +607,148 @@
 // code and returns the object parsed from it. parseLine never returns null,
 // the object will be LDError if it could not be parsed properly.
 // =============================================================================
-LDObject* parseLine( str line )
-{
-	QStringList tokens = line.split( " ", str::SkipEmptyParts );
+LDObject* parseLine (str line) {
+	QStringList tokens = line.split (" ", str::SkipEmptyParts);
 	
-	if( tokens.size() <= 0 )
-	{
+	if (tokens.size() <= 0) {
 		// Line was empty, or only consisted of whitespace
 		return new LDEmptyObject;
 	}
 	
-	if( tokens[0].length() != 1 || tokens[0][0].isDigit() == false )
-		return new LDErrorObject( line, "Illogical line code" );
+	if (tokens[0].length() != 1 || tokens[0][0].isDigit() == false)
+		return new LDErrorObject (line, "Illogical line code");
 	
 	int num = tokens[0][0].digitValue();
-	switch (num)
-	{
-	case 0:
-		{
-			// Comment
-			str comm = line.mid( line.indexOf( "0" ) + 1 );
-			
-			// Remove any leading whitespace
-			while( comm[0] == ' ' )
-				comm.remove( 0, 1 );
-			
-			// Handle BFC statements
-			if (tokens.size() > 2 && tokens[1] == "BFC") {
-				for (short i = 0; i < LDBFCObject::NumStatements; ++i)
-					if (comm == fmt ("BFC %1", LDBFCObject::statements [i]))
-						return new LDBFCObject ((LDBFCObject::Type) i);
-				
-				// MLCAD is notorious for stuffing these statements in parts it
-				// creates. The above block only handles valid statements, so we
-				// need to handle MLCAD-style invertnext separately.
-				if (comm == "BFC CERTIFY INVERTNEXT")
-					return new LDBFCObject (LDBFCObject::InvertNext);
-			}
+	
+	switch (num) {
+	case 0: {
+		// Comment
+		str comm = line.mid (line.indexOf ("0") + 1);
+		
+		// Remove any leading whitespace
+		while (comm[0] == ' ')
+			comm.remove (0, 1);
+		
+		// Handle BFC statements
+		if (tokens.size() > 2 && tokens[1] == "BFC") {
+			for (short i = 0; i < LDBFCObject::NumStatements; ++i)
+				if (comm == fmt ("BFC %1", LDBFCObject::statements [i]))
+					return new LDBFCObject ( (LDBFCObject::Type) i);
 			
-			if (tokens.size() > 2 && tokens[1] == "!LDFORGE")
-			{
-				// Handle LDForge-specific types, they're embedded into comments too
-				if (tokens[2] == "VERTEX") {
-					// Vertex (0 !LDFORGE VERTEX)
-					CHECK_TOKEN_COUNT (7)
-					CHECK_TOKEN_NUMBERS (3, 6)
-					
-					LDVertexObject* obj = new LDVertexObject;
-					obj->setColor (tokens[3].toLong ());
-					
-					for (const Axis ax : g_Axes)
-						obj->pos[ax] = tokens[4 + ax].toDouble (); // 4 - 6
-					
-					return obj;
-				} elif (tokens[2] == "OVERLAY") {
-					CHECK_TOKEN_COUNT (9);
-					CHECK_TOKEN_NUMBERS (5, 8)
-					
-					LDOverlayObject* obj = new LDOverlayObject;
-					obj->setFilename( tokens[3] );
-					obj->setCamera( tokens[4].toLong() );
-					obj->setX( tokens[5].toLong() );
-					obj->setY( tokens[6].toLong() );
-					obj->setWidth( tokens[7].toLong() );
-					obj->setHeight( tokens[8].toLong() );
-					return obj;
-				}
+			// MLCAD is notorious for stuffing these statements in parts it
+			// creates. The above block only handles valid statements, so we
+			// need to handle MLCAD-style invertnext separately.
+			if (comm == "BFC CERTIFY INVERTNEXT")
+				return new LDBFCObject (LDBFCObject::InvertNext);
+		}
+		
+		if (tokens.size() > 2 && tokens[1] == "!LDFORGE") {
+			// Handle LDForge-specific types, they're embedded into comments too
+			if (tokens[2] == "VERTEX") {
+				// Vertex (0 !LDFORGE VERTEX)
+				CHECK_TOKEN_COUNT (7)
+				CHECK_TOKEN_NUMBERS (3, 6)
+				
+				LDVertexObject* obj = new LDVertexObject;
+				obj->setColor (tokens[3].toLong ());
+				
+				for (const Axis ax : g_Axes)
+					obj->pos[ax] = tokens[4 + ax].toDouble (); // 4 - 6
+				
+				return obj;
+			} elif (tokens[2] == "OVERLAY") {
+				CHECK_TOKEN_COUNT (9);
+				CHECK_TOKEN_NUMBERS (5, 8)
+				
+				LDOverlayObject* obj = new LDOverlayObject;
+				obj->setFilename (tokens[3]);
+				obj->setCamera (tokens[4].toLong());
+				obj->setX (tokens[5].toLong());
+				obj->setY (tokens[6].toLong());
+				obj->setWidth (tokens[7].toLong());
+				obj->setHeight (tokens[8].toLong());
+				return obj;
 			}
-			
-			// Just a regular comment:
-			LDCommentObject* obj = new LDCommentObject;
-			obj->text = comm;
-			return obj;
 		}
+		
+		// Just a regular comment:
+		LDCommentObject* obj = new LDCommentObject;
+		obj->text = comm;
+		return obj;
+	}
 	
-	case 1:
-		{
-			// Subfile
-			CHECK_TOKEN_COUNT( 15 )
-			CHECK_TOKEN_NUMBERS( 1, 13 )
-			
-			// Try open the file. Disable g_loadingMainFile temporarily since we're
-			// not loading the main file now, but the subfile in question.
-			bool tmp = g_loadingMainFile;
-			g_loadingMainFile = false;
-			LDOpenFile* load = getFile( tokens[14] );
-			g_loadingMainFile = tmp;
-			
-			// If we cannot open the file, mark it an error
-			if( !load )
-				return new LDErrorObject( line, "Could not open referred file" );
-			
-			LDSubfileObject* obj = new LDSubfileObject;
-			obj->setColor( tokens[1].toLong() );
-			obj->setPosition( parseVertex( tokens, 2 )); // 2 - 4
-			
-			matrix transform;
-			for( short i = 0; i < 9; ++i )
-				transform[i] = tokens[i + 5].toDouble(); // 5 - 13
-			
-			obj->setTransform( transform );
-			obj->setFileInfo( load );
-			return obj;
-		}
+	case 1: {
+		// Subfile
+		CHECK_TOKEN_COUNT (15)
+		CHECK_TOKEN_NUMBERS (1, 13)
+		
+		// Try open the file. Disable g_loadingMainFile temporarily since we're
+		// not loading the main file now, but the subfile in question.
+		bool tmp = g_loadingMainFile;
+		g_loadingMainFile = false;
+		LDOpenFile* load = getFile (tokens[14]);
+		g_loadingMainFile = tmp;
+		
+		// If we cannot open the file, mark it an error
+		if (!load)
+			return new LDErrorObject (line, "Could not open referred file");
+		
+		LDSubfileObject* obj = new LDSubfileObject;
+		obj->setColor (tokens[1].toLong());
+		obj->setPosition (parseVertex (tokens, 2));  // 2 - 4
+		
+		matrix transform;
+		
+		for (short i = 0; i < 9; ++i)
+			transform[i] = tokens[i + 5].toDouble(); // 5 - 13
+		
+		obj->setTransform (transform);
+		obj->setFileInfo (load);
+		return obj;
+	}
 	
-	case 2:
-		{
-			CHECK_TOKEN_COUNT( 8 )
-			CHECK_TOKEN_NUMBERS( 1, 7 )
-			
-			// Line
-			LDLineObject* obj = new LDLineObject;
-			obj->setColor( tokens[1].toLong() );
-			for( short i = 0; i < 2; ++i )
-				obj->setVertex( i, parseVertex( tokens, 2 + ( i * 3 ))); // 2 - 7
-			return obj;
-		}
+	case 2: {
+		CHECK_TOKEN_COUNT (8)
+		CHECK_TOKEN_NUMBERS (1, 7)
+		
+		// Line
+		LDLineObject* obj = new LDLineObject;
+		obj->setColor (tokens[1].toLong());
+		
+		for (short i = 0; i < 2; ++i)
+			obj->setVertex (i, parseVertex (tokens, 2 + (i * 3)));   // 2 - 7
+		
+		return obj;
+	}
 	
-	case 3:
-		{
-			CHECK_TOKEN_COUNT( 11 )
-			CHECK_TOKEN_NUMBERS( 1, 10 )
-			
-			// Triangle
-			LDTriangleObject* obj = new LDTriangleObject;
-			obj->setColor( tokens[1].toLong() );
-			
-			for( short i = 0; i < 3; ++i )
-				obj->setVertex( i, parseVertex( tokens, 2 + ( i * 3 ))); // 2 - 10
-			
-			return obj;
-		}
+	case 3: {
+		CHECK_TOKEN_COUNT (11)
+		CHECK_TOKEN_NUMBERS (1, 10)
+		
+		// Triangle
+		LDTriangleObject* obj = new LDTriangleObject;
+		obj->setColor (tokens[1].toLong());
+		
+		for (short i = 0; i < 3; ++i)
+			obj->setVertex (i, parseVertex (tokens, 2 + (i * 3)));   // 2 - 10
+		
+		return obj;
+	}
 	
 	case 4:
-	case 5:
-		{
-			CHECK_TOKEN_COUNT (14)
-			CHECK_TOKEN_NUMBERS (1, 13)
-			
-			// Quadrilateral / Conditional line
-			LDObject* obj = (num == 4) ? ((LDObject*) new LDQuadObject ) : ((LDObject*) new LDCondLineObject);
-			obj->setColor( tokens[1].toLong() );
-			
-			for (short i = 0; i < 4; ++i)
-				obj->setVertex( i, parseVertex( tokens, 2 + ( i * 3 ))); // 2 - 13
-			
-			return obj;
-		}
+	case 5: {
+		CHECK_TOKEN_COUNT (14)
+		CHECK_TOKEN_NUMBERS (1, 13)
+		
+		// Quadrilateral / Conditional line
+		LDObject* obj = (num == 4) ? ( (LDObject*) new LDQuadObject) : ( (LDObject*) new LDCondLineObject);
+		obj->setColor (tokens[1].toLong());
+		
+		for (short i = 0; i < 4; ++i)
+			obj->setVertex (i, parseVertex (tokens, 2 + (i * 3)));   // 2 - 13
+		
+		return obj;
+	}
 	
 	default: // Strange line we couldn't parse
 		return new LDErrorObject (line, "Unknown line code number");
@@ -772,14 +758,13 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-LDOpenFile* getFile( str filename )
-{
+LDOpenFile* getFile (str filename) {
 	// Try find the file in the list of loaded files
-	LDOpenFile* load = findLoadedFile( filename );
+	LDOpenFile* load = findLoadedFile (filename);
 	
 	// If it's not loaded, try open it
-	if( !load )
-		load = openDATFile( filename, true );
+	if (!load)
+		load = openDATFile (filename, true);
 	
 	return load;
 }
@@ -788,30 +773,28 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void reloadAllSubfiles () {
-	if( !g_curfile )
+	if (!g_curfile)
 		return;
 	
 	g_loadedFiles.clear();
 	g_loadedFiles << g_curfile;
 	
 	// Go through all objects in the current file and reload the subfiles
-	for( LDObject* obj : g_curfile->objs() )
-	{
-		if( obj->getType() == LDObject::Subfile )
-		{
-			LDSubfileObject* ref = static_cast<LDSubfileObject*>( obj );
-			LDOpenFile* fileInfo = getFile( ref->fileInfo()->name() );
+	for (LDObject* obj : g_curfile->objs()) {
+		if (obj->getType() == LDObject::Subfile) {
+			LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj);
+			LDOpenFile* fileInfo = getFile (ref->fileInfo()->name());
 			
 			if (fileInfo)
-				ref->setFileInfo( fileInfo );
+				ref->setFileInfo (fileInfo);
 			else
-				ref->replace( new LDErrorObject( ref->raw(), "Could not open referred file" ));
+				ref->replace (new LDErrorObject (ref->raw(), "Could not open referred file"));
 		}
 		
 		// Reparse gibberish files. It could be that they are invalid because
 		// of loading errors. Circumstances may be different now.
-		if( obj->getType() == LDObject::Error )
-			obj->replace( parseLine( static_cast<LDErrorObject*>( obj )->contents ));
+		if (obj->getType() == LDObject::Error)
+			obj->replace (parseLine (static_cast<LDErrorObject*> (obj)->contents));
 	}
 	
 	// Close all files left unused
@@ -821,16 +804,15 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-ulong LDOpenFile::addObject (LDObject* obj)
-{
-	PROP_NAME( history ).add( new AddHistory( PROP_NAME( objs ).size(), obj ));
-	PROP_NAME( objs ) << obj;
+ulong LDOpenFile::addObject (LDObject* obj) {
+	PROP_NAME (history).add (new AddHistory (PROP_NAME (objs).size(), obj));
+	PROP_NAME (objs) << obj;
 	
-	if( obj->getType() == LDObject::Vertex )
-		PROP_NAME( vertices ) << obj;
+	if (obj->getType() == LDObject::Vertex)
+		PROP_NAME (vertices) << obj;
 	
-	if( this == g_curfile )
-		g_BBox.calcObject( obj );
+	if (this == g_curfile)
+		g_BBox.calcObject (obj);
 	
 	return numObjs() - 1;
 }
@@ -839,30 +821,30 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void LDOpenFile::insertObj (const ulong pos, LDObject* obj) {
-	m_history.add( new AddHistory( pos, obj ));
-	m_objs.insert( pos, obj );
+	m_history.add (new AddHistory (pos, obj));
+	m_objs.insert (pos, obj);
 	
-	if( this == g_curfile )
-		g_BBox.calcObject( obj );
+	if (this == g_curfile)
+		g_BBox.calcObject (obj);
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void LDOpenFile::forgetObject( LDObject* obj ) {
-	ulong idx = obj->getIndex( this );
-	m_history.add( new DelHistory( idx, obj ));
-	m_objs.erase( idx );
+void LDOpenFile::forgetObject (LDObject* obj) {
+	ulong idx = obj->getIndex (this);
+	m_history.add (new DelHistory (idx, obj));
+	m_objs.erase (idx);
 	
 	// Update the bounding box
-	if( this == g_curfile )
+	if (this == g_curfile)
 		g_BBox.calculate ();
 }
 
 // =============================================================================
 bool safeToCloseAll () {
-	for( LDOpenFile* f : g_loadedFiles )
-		if( !f->safeToClose() )
+	for (LDOpenFile* f : g_loadedFiles)
+		if (!f->safeToClose())
 			return false;
 	
 	return true;
@@ -870,12 +852,12 @@
 
 // =============================================================================
 void LDOpenFile::setObject (ulong idx, LDObject* obj) {
-	assert( idx < numObjs() );
+	assert (idx < numObjs());
 	
 	// Mark this change to history
-	str oldcode = object( idx )->raw ();
+	str oldcode = object (idx)->raw ();
 	str newcode = obj->raw();
-	m_history << new EditHistory( idx, oldcode, newcode );
+	m_history << new EditHistory (idx, oldcode, newcode);
 	
 	m_objs[idx] = obj;
 }
@@ -883,14 +865,13 @@
 static vector<LDOpenFile*> getFilesUsed (LDOpenFile* node) {
 	vector<LDOpenFile*> filesUsed;
 	
-	for (LDObject* obj : *node)
-	{
-		if( obj->getType() != LDObject::Subfile )
+	for (LDObject* obj : *node) {
+		if (obj->getType() != LDObject::Subfile)
 			continue;
 		
-		LDSubfileObject* ref = static_cast<LDSubfileObject*>( obj );
+		LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj);
 		filesUsed << ref->fileInfo();
-		filesUsed << getFilesUsed( ref->fileInfo() );
+		filesUsed << getFilesUsed (ref->fileInfo());
 	}
 	
 	return filesUsed;
@@ -898,33 +879,29 @@
 
 // =============================================================================
 // Find out which files are unused and close them.
-void LDOpenFile::closeUnused ()
-{
+void LDOpenFile::closeUnused () {
 	vector<LDOpenFile*> filesUsed = getFilesUsed (g_curfile);
 	
 	// Anything that's explicitly opened must not be closed
-	for( LDOpenFile* file : g_loadedFiles )
-		if( !file->implicit() )
+	for (LDOpenFile* file : g_loadedFiles)
+		if (!file->implicit())
 			filesUsed << file;
 	
 	// Remove duplicated entries
 	filesUsed.makeUnique();
 	
 	// Close all open files that aren't in filesUsed
-	for( LDOpenFile* file : g_loadedFiles )
-	{
+	for (LDOpenFile* file : g_loadedFiles) {
 		bool isused = false;
-		
-		for( LDOpenFile* usedFile : filesUsed )
-		{
-			if( file == usedFile )
-			{
+	
+	for (LDOpenFile* usedFile : filesUsed) {
+			if (file == usedFile) {
 				isused = true;
 				break;
 			}
 		}
 		
-		if( !isused )
+		if (!isused)
 			delete file;
 	}
 	
@@ -932,17 +909,15 @@
 	g_loadedFiles << filesUsed;
 }
 
-LDObject* LDOpenFile::object( ulong pos ) const
-{
-	if( m_objs.size() <= pos )
+LDObject* LDOpenFile::object (ulong pos) const {
+	if (m_objs.size() <= pos)
 		return null;
 	
 	return m_objs[pos];
 }
 
-LDOpenFile& LDOpenFile::operator<<( vector<LDObject*> objs )
-{
-	for( LDObject* obj : objs )
+LDOpenFile& LDOpenFile::operator<< (vector<LDObject*> objs) {
+	for (LDObject* obj : objs)
 		m_objs << obj;
 	
 	return *this;
--- a/src/gldraw.cpp	Sat Jul 13 19:02:48 2013 +0300
+++ b/src/gldraw.cpp	Sat Jul 13 21:21:33 2013 +0300
@@ -1305,7 +1305,7 @@
 	if (obj->vertices() >= 2) {
 		for (int i = 0; i < obj->vertices(); ++i)
 			verts << obj->getVertex (i);
-	} elif( obj->getType() == LDObject::Subfile ) {
+	} elif (obj->getType() == LDObject::Subfile) {
 		vector<LDObject*> objs = static_cast<LDSubfileObject*> (obj)->inlineContents (true, true);
 		
 		for(LDObject* obj : objs) {
@@ -1389,7 +1389,7 @@
 
 // =============================================================================
 Axis GLRenderer::cameraAxis (bool y, GL::Camera camid) {
-	if( camid == (GL::Camera) -1 )
+	if (camid == (GL::Camera) -1)
 		camid = m_camera;
 	
 	const staticCameraMeta* cam = &g_staticCameras[camid];
@@ -1397,14 +1397,12 @@
 }
 
 // =============================================================================
-bool GLRenderer::setupOverlay ( GL::Camera cam, str file, int x, int y, int w, int h )
-{
-	QImage* img = new QImage( file );
-	overlayMeta& info = getOverlay( cam );
+bool GLRenderer::setupOverlay (GL::Camera cam, str file, int x, int y, int w, int h) {
+	QImage* img = new QImage (file);
+	overlayMeta& info = getOverlay (cam);
 	
-	if( img->isNull() )
-	{
-		critical( tr( "Failed to load overlay image!" ));
+	if (img->isNull()) {
+		critical (tr ("Failed to load overlay image!"));
 		delete img;
 		return false;
 	}
@@ -1418,31 +1416,30 @@
 	info.oy = y;
 	info.img = img;
 	
-	if( info.lw == 0 )
-		info.lw = ( info.lh * img->width() ) / img->height();
-	elif( info.lh == 0 )
-		info.lh = ( info.lw * img->height() ) / img->width();
+	if (info.lw == 0)
+		info.lw = (info.lh * img->width()) / img->height();
+	elif (info.lh == 0)
+		info.lh = (info.lw * img->height()) / img->width();
 	
-	const Axis x2d = cameraAxis( false, cam ),
-		y2d = cameraAxis( true, cam );
-	
+	const Axis x2d = cameraAxis (false, cam),
+		y2d = cameraAxis (true, cam);
+
 	double negXFac = g_staticCameras[cam].negX ? -1 : 1,
 		negYFac = g_staticCameras[cam].negY ? -1 : 1;
-	
+
 	info.v0 = info.v1 = g_origin;
-	info.v0[x2d] = -( info.ox * info.lw * negXFac ) / img->width();
-	info.v0[y2d] = ( info.oy * info.lh * negYFac ) / img->height();
+	info.v0[x2d] = - (info.ox * info.lw * negXFac) / img->width();
+	info.v0[y2d] = (info.oy * info.lh * negYFac) / img->height();
 	info.v1[x2d] = info.v0[x2d] + info.lw;
 	info.v1[y2d] = info.v0[y2d] + info.lh;
-	
+
 	// Set alpha of all pixels to 0.5
-	for( long i = 0; i < img->width(); ++i )
-	for( long j = 0; j < img->height(); ++j )
-	{
-		uint32 pixel = img->pixel( i, j );
-		img->setPixel( i, j, 0x80000000 | ( pixel & 0x00FFFFFF ));
+	for (long i = 0; i < img->width(); ++i)
+	for (long j = 0; j < img->height(); ++j) {
+		uint32 pixel = img->pixel (i, j);
+		img->setPixel (i, j, 0x80000000 | (pixel & 0x00FFFFFF));
 	}
-	
+
 	updateOverlayObjects();
 	return true;
 }
@@ -1609,15 +1606,12 @@
 	ev->accept();
 }
 
-LDOverlayObject* GLRenderer::findOverlayObject( GLRenderer::Camera cam )
-{
+LDOverlayObject* GLRenderer::findOverlayObject (GLRenderer::Camera cam) {
 	LDOverlayObject* ovlobj = null;
 	
-	for( LDObject* obj : *file() )
-	{
-		if( obj->getType() == LDObject::Overlay && static_cast<LDOverlayObject*>( obj )->camera() == cam )
-		{
-			ovlobj = static_cast<LDOverlayObject*>( obj );
+	for (LDObject * obj : *file()) {
+		if (obj->getType() == LDObject::Overlay && static_cast<LDOverlayObject*> (obj)->camera() == cam) {
+			ovlobj = static_cast<LDOverlayObject*> (obj);
 			break;
 		}
 	}
@@ -1631,52 +1625,44 @@
 // =============================================================================
 void GLRenderer::overlaysFromObjects()
 {
-	for( Camera cam : g_Cameras )
-	{
-		if( cam == Free )
+	for (Camera cam : g_Cameras) {
+		if (cam == Free)
 			continue;
 		
 		overlayMeta& meta = m_overlays[cam];
-		LDOverlayObject* ovlobj = findOverlayObject( cam );
+		LDOverlayObject* ovlobj = findOverlayObject (cam);
 		
-		if( !ovlobj && meta.img )
-		{
+		if (!ovlobj && meta.img) {
 			delete meta.img;
 			meta.img = null;
-		}
-		elif( ovlobj && ( !meta.img || meta.fname != ovlobj->filename() ))
-			setupOverlay( cam, ovlobj->filename(), ovlobj->x(), ovlobj->y(), ovlobj->width(), ovlobj->height() );
+		} elif (ovlobj && (!meta.img || meta.fname != ovlobj->filename()))
+			setupOverlay (cam, ovlobj->filename(), ovlobj->x(), ovlobj->y(), ovlobj->width(), ovlobj->height());
 	}
 }
 
 // =============================================================================
-void GLRenderer::updateOverlayObjects()
-{
-	for( Camera cam : g_Cameras )
-	{
-		if( cam == Free )
+void GLRenderer::updateOverlayObjects() {
+	for (Camera cam : g_Cameras) {
+		if (cam == Free)
 			continue;
 		
 		overlayMeta& meta = m_overlays[cam];
-		LDOverlayObject* ovlobj = findOverlayObject( cam );
+		LDOverlayObject* ovlobj = findOverlayObject (cam);
 		
-		if( !meta.img && ovlobj )
-		{
+		if (!meta.img && ovlobj) {
 			// If this is the last overlay image, we need to remove the empty space after it as well.
 			LDObject* nextobj = ovlobj->next();
-			if( nextobj && nextobj->getType() == LDObject::Empty )
-			{
-				m_file->forgetObject( nextobj );
+			
+			if (nextobj && nextobj->getType() == LDObject::Empty) {
+				m_file->forgetObject (nextobj);
 				delete nextobj;
 			}
 			
 			// If the overlay object was there and the overlay itself is
 			// not, remove the object.
-			m_file->forgetObject( ovlobj );
+			m_file->forgetObject (ovlobj);
 			delete ovlobj;
-		}
-		elif( meta.img && !ovlobj )
-		{
+		} elif (meta.img && !ovlobj) {
 			// Inverse case: image is there but the overlay object is
 			// not, thus create the object.
 			ovlobj = new LDOverlayObject;
@@ -1690,41 +1676,38 @@
 			ulong i, lastOverlay = -1u;
 			bool found = false;
 			
-			for( i = 0; i < file()->numObjs(); ++i )
-			{
-				LDObject* obj = file()->obj( i );
-				if( obj->isScemantic() )
-				{
+			for (i = 0; i < file()->numObjs(); ++i) {
+				LDObject* obj = file()->obj (i);
+				
+				if (obj->isScemantic()) {
 					found = true;
 					break;
 				}
 				
-				if( obj->getType() == LDObject::Overlay )
+				if (obj->getType() == LDObject::Overlay)
 					lastOverlay = i;
 			}
 			
-			if( lastOverlay != -1u )
-				file()->insertObj( lastOverlay + 1, ovlobj );
-			else
-			{
-				file()->insertObj( i, ovlobj );
+			if (lastOverlay != -1u)
+				file()->insertObj (lastOverlay + 1, ovlobj);
+			else {
+				file()->insertObj (i, ovlobj);
 				
-				if( found )
-					file()->insertObj( i + 1, new LDEmptyObject );
+				if (found)
+					file()->insertObj (i + 1, new LDEmptyObject);
 			}
 		}
 		
-		if( meta.img && ovlobj )
-		{
-			ovlobj->setCamera( cam );
-			ovlobj->setFilename( meta.fname );
-			ovlobj->setX( meta.ox );
-			ovlobj->setY( meta.oy );
-			ovlobj->setWidth( meta.lw );
-			ovlobj->setHeight( meta.lh );
+		if (meta.img && ovlobj) {
+			ovlobj->setCamera (cam);
+			ovlobj->setFilename (meta.fname);
+			ovlobj->setX (meta.ox);
+			ovlobj->setY (meta.oy);
+			ovlobj->setWidth (meta.lw);
+			ovlobj->setHeight (meta.lh);
 		}
 	}
 	
-	if( g_win->R() == this )
+	if (g_win->R() == this)
 		g_win->refresh();
 }
\ No newline at end of file

mercurial