- refactor

Mon, 04 Aug 2014 03:35:25 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 04 Aug 2014 03:35:25 +0300
changeset 859
ebc7a186699c
parent 858
b6b1afacb7c1
child 860
a496e72af069

- refactor

src/actionsEdit.cc file | annotate | diff | comparison | revisions
src/extPrograms.cc file | annotate | diff | comparison | revisions
src/glRenderer.cc file | annotate | diff | comparison | revisions
src/glRenderer.h file | annotate | diff | comparison | revisions
src/mainWindow.cc file | annotate | diff | comparison | revisions
src/miscallenous.cc file | annotate | diff | comparison | revisions
src/miscallenous.h file | annotate | diff | comparison | revisions
--- a/src/actionsEdit.cc	Tue Jul 29 13:16:48 2014 +0300
+++ b/src/actionsEdit.cc	Mon Aug 04 03:35:25 2014 +0300
@@ -360,7 +360,7 @@
 void doMoveObjects (Vertex vect)
 {
 	// Apply the grid values
-	vect *= *currentGrid().coordsnap;
+	vect *= *CurrentGrid().coordinateSnap;
 
 	for (LDObjectPtr obj : selection())
 		obj->move (vect);
@@ -425,8 +425,8 @@
 {
 	LDObjectList sel = selection();
 	QList<Vertex*> queue;
-	const Vertex rotpoint = rotPoint (sel);
-	const double angle = (pi * *currentGrid().anglesnap) / 180,
+	const Vertex rotpoint = GetRotationPoint (sel);
+	const double angle = (pi * *CurrentGrid().angleSnap) / 180,
 				 cosangle = cos (angle),
 				 sinangle = sin (angle);
 
@@ -511,7 +511,7 @@
 
 void MainWindow::slot_actionRotationPoint()
 {
-	configRotationPoint();
+	ConfigureRotationPoint();
 }
 
 // =============================================================================
@@ -531,8 +531,8 @@
 			Matrix t = mo->transform();
 
 			// Note: matrix values are to be rounded to 4 decimals.
-			v.apply ([](Axis, double& a) { roundToDecimals (a, cfg::RoundPosition); });
-			applyToMatrix (t, [](int, double& a) { roundToDecimals (a, cfg::RoundMatrix); });
+			v.apply ([](Axis, double& a) { RoundToDecimals (a, cfg::RoundPosition); });
+			applyToMatrix (t, [](int, double& a) { RoundToDecimals (a, cfg::RoundMatrix); });
 
 			mo->setPosition (v);
 			mo->setTransform (t);
@@ -543,7 +543,7 @@
 			for (int i = 0; i < obj->numVertices(); ++i)
 			{
 				Vertex v = obj->vertex (i);
-				v.apply ([](Axis, double& a) { roundToDecimals (a, cfg::RoundPosition); });
+				v.apply ([](Axis, double& a) { RoundToDecimals (a, cfg::RoundPosition); });
 				obj->setVertex (i, v);
 				num += 3;
 			}
--- a/src/extPrograms.cc	Tue Jul 29 13:16:48 2014 +0300
+++ b/src/extPrograms.cc	Mon Aug 04 03:35:25 2014 +0300
@@ -368,7 +368,7 @@
 		return;
 
 	// Compose the command-line arguments
-	QString argv = join (
+	QString argv = Join (
 	{
 		(axis == X) ? "-x" : (axis == Y) ? "-y" : "-z",
 		(mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r",
@@ -412,7 +412,7 @@
 		return;
 
 	// Compose arguments
-	QString argv = join (
+	QString argv = Join (
 	{
 		(not ui.cb_condense->isChecked()) ? "-q" : "",
 		(not ui.cb_subst->isChecked()) ? "-r" : "",
@@ -490,7 +490,7 @@
 		return;
 	}
 
-	QString parms = join (
+	QString parms = Join (
 	{
 		(ui.cb_colorize->isChecked()) ? "-c" : "",
 		(ui.cb_nocondense->isChecked()) ? "-t" : "",
@@ -498,7 +498,7 @@
 		ui.dsb_prescale->value()
 	});
 
-	QString argv_normal = join (
+	QString argv_normal = Join (
 	{
 		parms,
 		inDATName,
@@ -506,7 +506,7 @@
 		outDATName
 	});
 
-	QString argv_inverse = join (
+	QString argv_inverse = Join (
 	{
 		parms,
 		cutDATName,
@@ -526,7 +526,7 @@
 		insertOutput (outDAT2Name, false, {cutCol});
 
 	if (ui.cb_edges->isChecked() and checkProgPath (Isecalc) and
-		runUtilityProcess (Isecalc, cfg::IsecalcPath, join ( {inDATName, cutDATName, edgesDATName})))
+		runUtilityProcess (Isecalc, cfg::IsecalcPath, Join ({inDATName, cutDATName, edgesDATName})))
 	{
 		insertOutput (edgesDATName, false, {});
 	}
@@ -576,7 +576,7 @@
 		return;
 	}
 
-	QString argv = join (
+	QString argv = Join (
 	{
 		(ui.cb_oldsweep->isChecked() ? "-s" : ""),
 		(ui.cb_reverse->isChecked() ? "-r" : ""),
@@ -642,7 +642,7 @@
 		return;
 	}
 
-	QString argv = join (
+	QString argv = Join (
 	{
 		in1DATName,
 		in2DATName,
@@ -679,7 +679,7 @@
 
 	int unmatched = ui.unmatched->currentIndex();
 
-	QString argv = join (
+	QString argv = Join (
 	{
 		format ("-p %1", ui.precision->value()),
 		format ("-af %1", ui.flatAngle->value()),
--- a/src/glRenderer.cc	Tue Jul 29 13:16:48 2014 +0300
+++ b/src/glRenderer.cc	Mon Aug 04 03:35:25 2014 +0300
@@ -95,8 +95,6 @@
 	{ QColor (48,  112, 192), Vertex (0, 0, 10000) }, // Z
 };
 
-static GLuint g_GLAxes_VBO;
-static GLuint g_GLAxes_ColorVBO;
 static bool RendererInitialized (false);
 
 // =============================================================================
@@ -149,6 +147,9 @@
 	m_compiler->setRenderer (null);
 	delete m_compiler;
 	delete m_editmode;
+
+	glDeleteBuffers (1, &_axesVBO);
+	glDeleteBuffers (1, &_axesColorVBO);
 }
 
 // =============================================================================
@@ -279,11 +280,11 @@
 		}
 	}
 
-	glGenBuffers (1, &g_GLAxes_VBO);
-	glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO);
+	glGenBuffers (1, &_axesVBO);
+	glBindBuffer (GL_ARRAY_BUFFER, _axesVBO);
 	glBufferData (GL_ARRAY_BUFFER, sizeof axesdata, axesdata, GL_STATIC_DRAW);
-	glGenBuffers (1, &g_GLAxes_ColorVBO);
-	glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_ColorVBO);
+	glGenBuffers (1, &_axesColorVBO);
+	glBindBuffer (GL_ARRAY_BUFFER, _axesColorVBO);
 	glBufferData (GL_ARRAY_BUFFER, sizeof colordata, colordata, GL_STATIC_DRAW);
 	glBindBuffer (GL_ARRAY_BUFFER, 0);
 }
@@ -459,9 +460,9 @@
 
 		if (cfg::DrawAxes)
 		{
-			glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO);
+			glBindBuffer (GL_ARRAY_BUFFER, _axesVBO);
 			glVertexPointer (3, GL_FLOAT, 0, NULL);
-			glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO);
+			glBindBuffer (GL_ARRAY_BUFFER, _axesVBO);
 			glColorPointer (3, GL_FLOAT, 0, NULL);
 			glDrawArrays (GL_LINES, 0, 6);
 			checkGLError();
@@ -539,8 +540,8 @@
 	cx *= negXFac;
 	cy *= negYFac;
 
-	roundToDecimals (cx, 4);
-	roundToDecimals (cy, 4);
+	RoundToDecimals (cx, 4);
+	RoundToDecimals (cy, 4);
 
 	// Create the vertex from the coordinates
 	pos3d.setCoordinate (axisX, cx);
--- a/src/glRenderer.h	Tue Jul 29 13:16:48 2014 +0300
+++ b/src/glRenderer.h	Mon Aug 04 03:35:25 2014 +0300
@@ -233,6 +233,8 @@
 							m_totalmove;
 	QColor					m_bgcolor;
 	AbstractEditMode*		m_editmode;
+	GLuint					_axesVBO;
+	GLuint					_axesColorVBO;
 
 	void					calcCameraIcons();
 	void					clampAngle (double& angle) const;
--- a/src/mainWindow.cc	Tue Jul 29 13:16:48 2014 +0300
+++ b/src/mainWindow.cc	Mon Aug 04 03:35:25 2014 +0300
@@ -750,7 +750,7 @@
 		if (doc == getCurrentDocument())
 			updateTitle();
 
-		print ("Saved to %1 (%2)", path, prettyFileSize (savesize));
+		print ("Saved to %1 (%2)", path, MakePrettyFileSize (savesize));
 
 		// Add it to recent files
 		addRecentFile (path);
--- a/src/miscallenous.cc	Tue Jul 29 13:16:48 2014 +0300
+++ b/src/miscallenous.cc	Mon Aug 04 03:35:25 2014 +0300
@@ -27,7 +27,7 @@
 #include "ui_rotpoint.h"
 
 // Prime number table.
-const int g_primes[NUM_PRIMES] =
+const int PrimeNumbers[NUM_PRIMES] =
 {
 	2,    3,    5,    7,    11,   13,   17,   19,   23,   29,
 	31,   37,   41,   43,   47,   53,   59,   61,   67,   71,
@@ -81,7 +81,7 @@
 	3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571,
 };
 
-static const long g_e10[] =
+static const long E10[] =
 {
 	1l,
 	10l,
@@ -109,7 +109,7 @@
 CFGENTRY (Int, RotationPointType, 0)
 CFGENTRY (Vertex, CustomRotationPoint, g_origin)
 
-const gridinfo g_gridInfo[3] =
+const GridData Grids[3] =
 {
 	{ "Coarse",	&cfg::GridCoarseCoordinateSnap,	&cfg::GridCoarseAngleSnap	},
 	{ "Medium",	&cfg::GridMediumCoordinateSnap,	&cfg::GridMediumAngleSnap	},
@@ -122,7 +122,7 @@
 //
 double Grid::snap (double value, const Grid::Config type)
 {
-	double snapvalue = (type == Coordinate) ? *currentGrid().coordsnap : *currentGrid().anglesnap;
+	double snapvalue = (type == Coordinate) ? *CurrentGrid().coordinateSnap : *CurrentGrid().angleSnap;
 	double mult = floor (abs<double> (value / snapvalue));
 	double out = mult * snapvalue;
 
@@ -145,9 +145,9 @@
 	{
 		repeat = false;
 
-		for (int x = 0; x < countof (g_primes); x++)
+		for (int x = 0; x < countof (PrimeNumbers); x++)
 		{
-			int const prime = g_primes[x];
+			int const prime = PrimeNumbers[x];
 
 			if (numer < prime and denom < prime)
 				break;
@@ -165,11 +165,11 @@
 
 // =============================================================================
 //
-Vertex rotPoint (const LDObjectList& objs)
+Vertex GetRotationPoint (const LDObjectList& objs)
 {
-	switch ((ERotationPoint) cfg::RotationPointType)
+	switch (RotationPoint (cfg::RotationPointType))
 	{
-		case EObjectOrigin:
+		case RotationPoint::ObjectOrigin:
 		{
 			LDBoundingBox box;
 
@@ -185,15 +185,13 @@
 			return box.center();
 		}
 
-		case EWorldOrigin:
-		{
+		case RotationPoint::WorldOrigin:
 			return g_origin;
-		}
 
-		case ECustomPoint:
-		{
+		case RotationPoint::CustomPoint:
 			return cfg::CustomRotationPoint;
-		}
+
+		case RotationPoint::NumValues: break;
 	}
 
 	return Vertex();
@@ -201,25 +199,27 @@
 
 // =============================================================================
 //
-void configRotationPoint()
+void ConfigureRotationPoint()
 {
 	QDialog* dlg = new QDialog;
 	Ui::RotPointUI ui;
 	ui.setupUi (dlg);
 
-	switch ((ERotationPoint) cfg::RotationPointType)
+	switch (RotationPoint (cfg::RotationPointType))
 	{
-		case EObjectOrigin:
+		case RotationPoint::ObjectOrigin:
 			ui.objectPoint->setChecked (true);
 			break;
 
-		case EWorldOrigin:
+		case RotationPoint::WorldOrigin:
 			ui.worldPoint->setChecked (true);
 			break;
 
-		case ECustomPoint:
+		case RotationPoint::CustomPoint:
 			ui.customPoint->setChecked (true);
 			break;
+
+		case RotationPoint::NumValues: break;
 	}
 
 	ui.customX->setValue (cfg::CustomRotationPoint.x());
@@ -229,10 +229,10 @@
 	if (not dlg->exec())
 		return;
 
-	cfg::RotationPointType =
-		(ui.objectPoint->isChecked()) ? EObjectOrigin :
-		(ui.worldPoint->isChecked())  ? EWorldOrigin :
-		ECustomPoint;
+	cfg::RotationPointType = int (
+		(ui.objectPoint->isChecked()) ? RotationPoint::ObjectOrigin :
+		(ui.worldPoint->isChecked())  ? RotationPoint::WorldOrigin :
+		RotationPoint::CustomPoint);
 
 	cfg::CustomRotationPoint.setX (ui.customX->value());
 	cfg::CustomRotationPoint.setY (ui.customY->value());
@@ -241,7 +241,7 @@
 
 // =============================================================================
 //
-QString join (QList<StringFormatArg> vals, QString delim)
+QString Join (QList<StringFormatArg> vals, QString delim)
 {
 	QStringList list;
 
@@ -253,10 +253,10 @@
 
 // =============================================================================
 //
-void roundToDecimals (double& a, int decimals)
+void RoundToDecimals (double& a, int decimals)
 {
-	assert (decimals >= 0 and decimals < (signed) (sizeof g_e10 / sizeof *g_e10));
-	a = round (a * g_e10[decimals]) / g_e10[decimals];
+	assert (decimals >= 0 and decimals < (signed) (sizeof E10 / sizeof *E10));
+	a = round (a * E10[decimals]) / E10[decimals];
 }
 
 // =============================================================================
@@ -277,7 +277,7 @@
 
 // =============================================================================
 //
-double getCoordinate (const Vertex& a, Axis ax)
+double GetCoordinateOf (const Vertex& a, Axis ax)
 {
 	switch (ax)
 	{
@@ -293,7 +293,7 @@
 
 // =============================================================================
 //
-QString prettyFileSize (qint64 size)
+QString MakePrettyFileSize (qint64 size)
 {
 	QString result;
 
--- a/src/miscallenous.h	Tue Jul 29 13:16:48 2014 +0300
+++ b/src/miscallenous.h	Mon Aug 04 03:35:25 2014 +0300
@@ -30,7 +30,7 @@
 class QAction;
 
 // Prime numbers
-extern const int g_primes[NUM_PRIMES];
+extern const int PrimeNumbers[NUM_PRIMES];
 
 // Simplifies the given fraction.
 void simplify (int& numer, int& denom);
@@ -38,41 +38,42 @@
 using ApplyToMatrixFunction = std::function<void (int, double&)>;
 using ApplyToMatrixConstFunction = std::function<void (int, double)>;
 
-void roundToDecimals (double& a, int decimals);
+void RoundToDecimals (double& a, int decimals);
 void applyToMatrix (Matrix& a, ApplyToMatrixFunction func);
 void applyToMatrix (const Matrix& a, ApplyToMatrixConstFunction func);
 
-double getCoordinate (const Vertex& a, Axis ax);
-QString join (QList< StringFormatArg > vals, QString delim = " ");
-QString prettyFileSize (qint64 size);
+double GetCoordinateOf (const Vertex& a, Axis ax);
+QString MakePrettyFileSize (qint64 size);
+
+QString Join (QList<StringFormatArg> vals, QString delim = "");
 
 // Grid stuff
-struct gridinfo
+struct GridData
 {
-	const char*				name;
-	AbstractConfigEntry::FloatType*	coordsnap;
-	AbstractConfigEntry::FloatType*	anglesnap;
+	const char* name;
+	float* coordinateSnap;
+	float* angleSnap;
 };
 
 EXTERN_CFGENTRY (Int, Grid)
-static const int g_numGrids = 3;
-extern const gridinfo g_gridInfo[3];
+extern const GridData Grids[3];
 
-inline const gridinfo& currentGrid()
+inline const GridData& CurrentGrid()
 {
-	return g_gridInfo[cfg::Grid];
+	return Grids[cfg::Grid];
 }
 
 // =============================================================================
-enum ERotationPoint
+enum class RotationPoint
 {
-	EObjectOrigin,
-	EWorldOrigin,
-	ECustomPoint
+	ObjectOrigin,
+	WorldOrigin,
+	CustomPoint,
+	NumValues
 };
 
-Vertex rotPoint (const LDObjectList& objs);
-void configRotationPoint();
+Vertex GetRotationPoint (const LDObjectList& objs);
+void ConfigureRotationPoint();
 
 // =============================================================================
 namespace Grid

mercurial