Further improved enum handling

Sun, 08 May 2016 16:26:16 +0300

author
Teemu Piippo <teemu@compsta2.com>
date
Sun, 08 May 2016 16:26:16 +0300
changeset 1035
8a60250175ba
parent 1034
a05fc8256a3a
child 1036
993c46d7eb75

Further improved enum handling

src/glCompiler.cpp file | annotate | diff | comparison | revisions
src/glRenderer.cpp file | annotate | diff | comparison | revisions
src/glRenderer.h file | annotate | diff | comparison | revisions
src/glShared.h file | annotate | diff | comparison | revisions
src/mathfunctions.cpp file | annotate | diff | comparison | revisions
src/mathfunctions.h file | annotate | diff | comparison | revisions
src/toolsets/movetoolset.cpp file | annotate | diff | comparison | revisions
--- a/src/glCompiler.cpp	Sun May 08 16:11:40 2016 +0300
+++ b/src/glCompiler.cpp	Sun May 08 16:26:16 2016 +0300
@@ -118,7 +118,6 @@
 	switch (complement)
 	{
 	case SurfacesVboComplement:
-	case NumVboComplements:
 		return QColor();
 
 	case BfcFrontColorsVboComplement:
@@ -356,7 +355,7 @@
 	default: return;
 	}
 
-	for (ComplementVboType complement = FirstVboComplement; complement < NumVboComplements; ++complement)
+	for_enum(ComplementVboType, complement)
 	{
 		const int vbonum = vboNumber (surface, complement);
 		QVector<GLfloat>& vbodata = objinfo->data[vbonum];
@@ -391,7 +390,7 @@
 
 int GLCompiler::vboNumber (SurfaceVboType surface, ComplementVboType complement)
 {
-	return (surface * NumVboComplements) + complement;
+	return (surface * ENUM_LIMIT(ComplementVboType, Count)) + complement;
 }
 
 
--- a/src/glRenderer.cpp	Sun May 08 16:11:40 2016 +0300
+++ b/src/glRenderer.cpp	Sun May 08 16:26:16 2016 +0300
@@ -43,7 +43,7 @@
 #include "documentmanager.h"
 #include "grid.h"
 
-const CameraInfo g_cameraInfo[NumCameras] =
+const CameraInfo g_cameraInfo[ENUM_LIMIT(Camera, Count)] =
 {
 	{{  1,  0, 0 }, X, Z, false, false, false }, // top
 	{{  0,  0, 0 }, X, Y, false,  true, false }, // front
@@ -100,18 +100,18 @@
 	connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer()));
 
 	// Init camera icons
-	for (Camera cam = EFirstCamera; cam < NumCameras; ++cam)
+	for_enum(Camera, camera)
 	{
-		const char* cameraIconNames[NumCameras] =
+		const char* cameraIconNames[ENUM_LIMIT(Camera, Count)] =
 		{
 			"camera-top", "camera-front", "camera-left",
 			"camera-bottom", "camera-back", "camera-right",
 			"camera-free"
 		};
 
-		CameraIcon* info = &m_cameraIcons[cam];
-		info->image = GetIcon (cameraIconNames[cam]);
-		info->camera = cam;
+		CameraIcon* info = &m_cameraIcons[camera];
+		info->image = GetIcon (cameraIconNames[camera]);
+		info->camera = camera;
 	}
 
 	calcCameraIcons();
@@ -1428,7 +1428,7 @@
 //
 void GLRenderer::initOverlaysFromObjects()
 {
-	for (Camera camera = EFirstCamera; camera < NumCameras; ++camera)
+	for_enum(Camera, camera)
 	{
 		if (camera == FreeCamera)
 			continue;
@@ -1457,13 +1457,13 @@
 //
 void GLRenderer::updateOverlayObjects()
 {
-	for (Camera cam = EFirstCamera; cam < NumCameras; ++cam)
+	for_enum(Camera, camera)
 	{
-		if (cam == FreeCamera)
+		if (camera == FreeCamera)
 			continue;
 
-		LDGLOverlay& meta = currentDocumentData().overlays[cam];
-		LDOverlay* ovlobj = findOverlayObject (cam);
+		LDGLOverlay& meta = currentDocumentData().overlays[camera];
+		LDOverlay* ovlobj = findOverlayObject (camera);
 
 		if (meta.image == nullptr and ovlobj)
 		{
@@ -1519,7 +1519,7 @@
 
 		if (meta.image and ovlobj)
 		{
-			ovlobj->setCamera (cam);
+			ovlobj->setCamera (camera);
 			ovlobj->setFileName (meta.fileName);
 			ovlobj->setX (meta.offsetX);
 			ovlobj->setY (meta.offsetY);
@@ -1607,7 +1607,7 @@
 
 const CameraInfo& GLRenderer::cameraInfo (Camera camera) const
 {
-	if (camera >= EFirstCamera and camera <= ELastFixedCamera)
+	if (valueInEnum<Camera>(camera))
 		return g_cameraInfo[camera];
 	else
 		return g_cameraInfo[0];
--- a/src/glRenderer.h	Sun May 08 16:11:40 2016 +0300
+++ b/src/glRenderer.h	Sun May 08 16:26:16 2016 +0300
@@ -112,10 +112,6 @@
 	BackCamera,
 	RightCamera,
 	FreeCamera,
-
-	NumCameras,
-	ELastFixedCamera = RightCamera,
-	EFirstCamera = TopCamera
 };
 
 MAKE_ITERABLE_ENUM(Camera, TopCamera, FreeCamera)
--- a/src/glShared.h	Sun May 08 16:11:40 2016 +0300
+++ b/src/glShared.h	Sun May 08 16:26:16 2016 +0300
@@ -44,9 +44,6 @@
 	TrianglesVbo,
 	QuadsVbo,
 	ConditionalLinesVbo,
-
-	NumSurfaceVbos,
-	FirstSurfaceVbo = LinesVbo
 };
 
 MAKE_ITERABLE_ENUM (SurfaceVboType, LinesVbo, ConditionalLinesVbo)
@@ -59,9 +56,6 @@
 	BfcFrontColorsVboComplement,
 	BfcBackColorsVboComplement,
 	RandomColorsVboComplement,
-
-	NumVboComplements,
-	FirstVboComplement = SurfacesVboComplement
 };
 
 MAKE_ITERABLE_ENUM (ComplementVboType, SurfacesVboComplement, RandomColorsVboComplement)
--- a/src/mathfunctions.cpp	Sun May 08 16:11:40 2016 +0300
+++ b/src/mathfunctions.cpp	Sun May 08 16:26:16 2016 +0300
@@ -87,7 +87,7 @@
 {
 	switch (RotationPoint (m_config->rotationPointType()))
 	{
-	case RotationPoint::ObjectOrigin:
+	case ObjectOrigin:
 		{
 			BoundingBox box;
 
@@ -103,14 +103,11 @@
 			return box.center();
 		}
 
-	case RotationPoint::WorldOrigin:
+	case WorldOrigin:
 		return Vertex();
 
-	case RotationPoint::CustomPoint:
+	case CustomPoint:
 		return m_config->customRotationPoint();
-
-	case RotationPoint::NumValues:
-		break;
 	}
 
 	return Vertex();
--- a/src/mathfunctions.h	Sun May 08 16:11:40 2016 +0300
+++ b/src/mathfunctions.h	Sun May 08 16:26:16 2016 +0300
@@ -20,12 +20,11 @@
 #include "main.h"
 
 
-enum class RotationPoint
+enum RotationPoint
 {
 	ObjectOrigin,
 	WorldOrigin,
 	CustomPoint,
-	NumValues
 };
 
 
--- a/src/toolsets/movetoolset.cpp	Sun May 08 16:11:40 2016 +0300
+++ b/src/toolsets/movetoolset.cpp	Sun May 08 16:26:16 2016 +0300
@@ -179,20 +179,17 @@
 
 	switch (RotationPoint(m_config->rotationPointType()))
 	{
-	case RotationPoint::ObjectOrigin:
+	case ObjectOrigin:
 		ui.objectPoint->setChecked (true);
 		break;
 
-	case RotationPoint::WorldOrigin:
+	case WorldOrigin:
 		ui.worldPoint->setChecked (true);
 		break;
 
-	case RotationPoint::CustomPoint:
+	case CustomPoint:
 		ui.customPoint->setChecked (true);
 		break;
-
-	case RotationPoint::NumValues:
-		break;
 	}
 
 	Vertex custompoint = m_config->customRotationPoint();
@@ -205,11 +202,11 @@
 		RotationPoint pointType;
 
 		if (ui.objectPoint->isChecked())
-			pointType = RotationPoint::ObjectOrigin;
+			pointType = ObjectOrigin;
 		else if (ui.objectPoint->isChecked())
-			pointType = RotationPoint::WorldOrigin;
+			pointType = WorldOrigin;
 		else
-			pointType = RotationPoint::CustomPoint;
+			pointType = CustomPoint;
 
 		custompoint.setX (ui.customX->value());
 		custompoint.setY (ui.customY->value());

mercurial