Sun, 12 Feb 2017 16:02:02 +0200
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
--- a/src/basics.h Fri Feb 10 23:06:24 2017 +0200 +++ b/src/basics.h Sun Feb 12 16:02:02 2017 +0200 @@ -197,7 +197,7 @@ Iterator end() { - return Iterator(EnumLimits<Enum>::End); + return Iterator(EnumLimits<Enum>::Last + 1); } }; @@ -209,9 +209,10 @@ // Is a value inside an enum? template<typename Enum> -bool valueInEnum(typename std::underlying_type<Enum>::type x) +bool valueInEnum(Enum enumerator) { - return x >= EnumLimits<Enum>::First and x <= EnumLimits<Enum>::Last; + typename std::underlying_type<Enum>::type index = static_cast<typename std::underlying_type<Enum>::type>(enumerator); + return index >= EnumLimits<Enum>::First and index <= EnumLimits<Enum>::Last; } double getRadialPoint(int segment, int divisions, double(*func)(double));
--- a/src/canvas.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/canvas.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -51,7 +51,7 @@ } #endif - if (camera() != FreeCamera) + if (camera() != Camera::Free) { // Paint the coordinates onto the screen. QString text = format(tr("X: %1, Y: %2, Z: %3"), m_position3D[X], m_position3D[Y], m_position3D[Z]); @@ -101,8 +101,8 @@ m_currentEditMode = AbstractEditMode::createByType(this, a); // If we cannot use the free camera, use the top one instead. - if (camera() == FreeCamera and not m_currentEditMode->allowFreeCamera()) - setCamera(TopCamera); + if (camera() == Camera::Free and not m_currentEditMode->allowFreeCamera()) + setCamera(Camera::Top); m_window->updateEditModeActions(); update(); @@ -234,16 +234,16 @@ // void Canvas::setDepthValue (double depth) { - if (camera() < FreeCamera) - m_depthValues[camera()] = depth; + if (camera() < Camera::Free) + m_depthValues[static_cast<int>(camera())] = depth; } // ============================================================================= // double Canvas::getDepthValue() const { - if (camera() < FreeCamera) - return m_depthValues[camera()]; + if (camera() < Camera::Free) + return m_depthValues[static_cast<int>(camera())]; else return 0.0; } @@ -253,7 +253,7 @@ */ Vertex Canvas::convert2dTo3d(const QPoint& position2d, bool snap) const { - if (camera() == FreeCamera) + if (camera() == Camera::Free) { return {0, 0, 0}; } @@ -294,7 +294,7 @@ */ QPoint Canvas::convert3dTo2d(const Vertex& position3d) const { - if (camera() == FreeCamera) + if (camera() == Camera::Free) { return {0, 0}; }
--- a/src/documentloader.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/documentloader.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -116,7 +116,7 @@ LDObject* obj = _model->addFromString(line); // Check for parse errors and warn about them - if (obj->type() == OBJ_Error) + if (obj->type() == LDObjectType::Error) { print ("Couldn't parse line #%1: %2", progress() + 1, static_cast<LDError*> (obj)->reason()); ++m_warningCount;
--- a/src/documentmanager.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/documentmanager.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -133,7 +133,7 @@ for (LDObject* obj : file->objects()) { - if (obj->type() != OBJ_Error or static_cast<LDError*> (obj)->fileReferenced().isEmpty()) + if (obj->type() != LDObjectType::Error or static_cast<LDError*> (obj)->fileReferenced().isEmpty()) continue; unknowns << static_cast<LDError*> (obj)->fileReferenced();
--- a/src/editmodes/circleMode.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/editmodes/circleMode.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -71,13 +71,13 @@ { 0, 1, 0, 2, 0, 0, 0, 0, 2 }, }; - Matrix transform = templates[renderer()->camera() % 3]; + Matrix transform = templates[static_cast<int>(renderer()->camera()) % 3]; for (double& value : transform) { if (value == 2) value = scale; - else if (value == 1 and renderer()->camera() >= 3) + else if (value == 1 and static_cast<int>(renderer()->camera()) >= 3) value = -1; } @@ -164,7 +164,7 @@ quad->setColor(MainColor); // Ensure the quads always are BFC-front towards the camera - if (renderer()->camera() % 3 <= 0) + if (static_cast<int>(renderer()->camera()) % 3 <= 0) quad->invert(); } }
--- a/src/editmodes/magicWandMode.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/editmodes/magicWandMode.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -46,7 +46,7 @@ // of candidates. for (LDObject* candidate : candidates) { - if (not isOneOf (candidate->type(), OBJ_Line, OBJ_CondLine) or candidate->vertex (0) == candidate->vertex (1)) + if (not isOneOf (candidate->type(), LDObjectType::Line, LDObjectType::CondLine) or candidate->vertex (0) == candidate->vertex (1)) continue; int matches = 0; @@ -60,7 +60,7 @@ { // Boundary found. If it's an edgeline, add it to the boundaries list, if a // conditional line, select it. - if (candidate->type() == OBJ_CondLine) + if (candidate->type() == LDObjectType::CondLine) m_selection << candidate; else boundaries.append (std::make_tuple (candidate->vertex (0), candidate->vertex (1))); @@ -96,13 +96,13 @@ switch (obj->type()) { - case OBJ_Line: - case OBJ_CondLine: + case LDObjectType::Line: + case LDObjectType::CondLine: matchesneeded = 1; break; - case OBJ_Triangle: - case OBJ_Quad: + case LDObjectType::Triangle: + case LDObjectType::Quad: matchesneeded = 2; break;
--- a/src/glCompiler.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/glCompiler.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -107,7 +107,7 @@ } -QColor GLCompiler::getColorForPolygon (LDPolygon& poly, LDObject* topobj, ComplementVboType complement) const +QColor GLCompiler::getColorForPolygon (LDPolygon& poly, LDObject* topobj, VboSubclass complement) const { QColor qcol; static const QColor bfcFrontColor {64, 192, 80}; @@ -115,26 +115,27 @@ switch (complement) { - case SurfacesVboComplement: - case NormalsVboComplement: + case VboSubclass::Surfaces: + case VboSubclass::Normals: + case VboSubclass::_End: return {}; - case BfcFrontColorsVboComplement: + case VboSubclass::BfcFrontColors: qcol = bfcFrontColor; break; - case BfcBackColorsVboComplement: + case VboSubclass::BfcBackColors: qcol = bfcBackColor; break; - case PickColorsVboComplement: + case VboSubclass::PickColors: return indexColorForID(topobj->id()); - case RandomColorsVboComplement: + case VboSubclass::RandomColors: qcol = topobj->randomColor(); break; - case NormalColorsVboComplement: + case VboSubclass::NormalColors: if (poly.color == MainColor) { if (topobj->color() == MainColor) @@ -286,10 +287,10 @@ { // Note: We cannot split quads into triangles here, it would mess up the wireframe view. // Quads must go into separate vbos. - case OBJ_Triangle: - case OBJ_Quad: - case OBJ_Line: - case OBJ_CondLine: + case LDObjectType::Triangle: + case LDObjectType::Quad: + case LDObjectType::Line: + case LDObjectType::CondLine: { LDPolygon* poly = obj->getPolygon(); poly->id = obj->id(); @@ -298,7 +299,7 @@ break; } - case OBJ_SubfileReference: + case LDObjectType::SubfileReference: { LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj); auto data = ref->inlinePolygons(); @@ -311,7 +312,7 @@ break; } - case OBJ_BezierCurve: + case LDObjectType::BezierCurve: { LDBezierCurve* curve = static_cast<LDBezierCurve*> (obj); for (LDPolygon& polygon : curve->rasterizePolygons(grid()->bezierCurveSegments())) @@ -333,15 +334,15 @@ void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo) { - SurfaceVboType surface; + VboClass surface; int vertexCount; switch (poly.num) { - case 2: surface = LinesVbo; vertexCount = 2; break; - case 3: surface = TrianglesVbo; vertexCount = 3; break; - case 4: surface = QuadsVbo; vertexCount = 4; break; - case 5: surface = ConditionalLinesVbo; vertexCount = 2; break; + case 2: surface = VboClass::Lines; vertexCount = 2; break; + case 3: surface = VboClass::Triangles; vertexCount = 3; break; + case 4: surface = VboClass::Quads; vertexCount = 4; break; + case 5: surface = VboClass::ConditionalLines; vertexCount = 2; break; default: return; } @@ -357,7 +358,7 @@ normals[i] = Vertex::crossProduct(v3 - v2, v1 - v2).normalized(); } - for (ComplementVboType complement : iterateEnum<ComplementVboType>()) + for (VboSubclass complement : iterateEnum<VboSubclass>()) { const int vbonum = vboNumber (surface, complement); QVector<GLfloat>& vbodata = objinfo->data[vbonum]; @@ -365,14 +366,14 @@ for (int vert = 0; vert < vertexCount; ++vert) { - if (complement == SurfacesVboComplement) + if (complement == VboSubclass::Surfaces) { // Write coordinates. Apparently Z must be flipped too? vbodata << poly.vertices[vert].x() << -poly.vertices[vert].y() << -poly.vertices[vert].z(); } - else if (complement == NormalsVboComplement) + else if (complement == VboSubclass::Normals) { vbodata << normals[vert].x() << -normals[vert].y() @@ -396,9 +397,9 @@ } -int GLCompiler::vboNumber (SurfaceVboType surface, ComplementVboType complement) +int GLCompiler::vboNumber (VboClass surface, VboSubclass complement) { - return (surface * EnumLimits<ComplementVboType>::Count) + complement; + return (static_cast<int>(surface) * EnumLimits<VboSubclass>::Count) + static_cast<int>(complement); }
--- a/src/glCompiler.h Fri Feb 10 23:06:24 2017 +0200 +++ b/src/glCompiler.h Sun Feb 12 16:02:02 2017 +0200 @@ -38,7 +38,7 @@ GLCompiler (GLRenderer* renderer); ~GLCompiler(); - QColor getColorForPolygon (LDPolygon& poly, LDObject* topobj, ComplementVboType complement) const; + QColor getColorForPolygon (LDPolygon& poly, LDObject* topobj, VboSubclass complement) const; QColor indexColorForID (int id) const; void initialize(); void needMerge(); @@ -49,7 +49,7 @@ GLuint vbo (int vbonum) const; int vboSize (int vbonum) const; - static int vboNumber (SurfaceVboType surface, ComplementVboType complement); + static int vboNumber (VboClass surface, VboSubclass complement); private: void compileStaged();
--- a/src/glRenderer.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/glRenderer.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -92,8 +92,8 @@ "camera-free" }; - CameraIcon* info = &m_cameraIcons[camera]; - info->image = GetIcon (cameraIconNames[camera]); + CameraIcon* info = &m_cameraIcons[static_cast<int>(camera)]; + info->image = GetIcon (cameraIconNames[static_cast<int>(camera)]); info->camera = camera; } @@ -121,7 +121,7 @@ for (CameraIcon& info : m_cameraIcons) { // MATH - int x1 = (width() - (info.camera != FreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1; + int x1 = (width() - (info.camera != Camera::Free ? 48 : 16)) + ((i % 3) * 16) - 1; int y1 = ((i / 3) * 16) + 1; info.sourceRect = QRect (0, 0, 16, 16); @@ -378,7 +378,7 @@ else glDisable(GL_LIGHTING); - if (camera() != FreeCamera) + if (camera() != Camera::Free) { glMatrixMode (GL_PROJECTION); glPushMatrix(); @@ -387,15 +387,15 @@ glOrtho (-m_virtualWidth, m_virtualWidth, -m_virtualHeight, m_virtualHeight, -100.0f, 100.0f); glTranslatef(panning (X), panning (Y), 0.0f); - if (camera() != FrontCamera and camera() != BackCamera) + if (camera() != Camera::Front and camera() != Camera::Back) { - glRotatef(90.0f, g_cameraInfo[camera()].glrotate[0], - g_cameraInfo[camera()].glrotate[1], - g_cameraInfo[camera()].glrotate[2]); + glRotatef(90.0f, g_cameraInfo[static_cast<int>(camera())].glrotate[0], + g_cameraInfo[static_cast<int>(camera())].glrotate[1], + g_cameraInfo[static_cast<int>(camera())].glrotate[2]); } // Back camera needs to be handled differently - if (camera() == BackCamera) + if (camera() == Camera::Back) { glRotatef(180.0f, 1.0f, 0.0f, 0.0f); glRotatef(180.0f, 0.0f, 0.0f, 1.0f); @@ -417,10 +417,10 @@ if (m_isDrawingSelectionScene) { - drawVbos (TrianglesVbo, PickColorsVboComplement, GL_TRIANGLES); - drawVbos (QuadsVbo, PickColorsVboComplement, GL_QUADS); - drawVbos (LinesVbo, PickColorsVboComplement, GL_LINES); - drawVbos (ConditionalLinesVbo, PickColorsVboComplement, GL_LINES); + drawVbos (VboClass::Triangles, VboSubclass::PickColors, GL_TRIANGLES); + drawVbos (VboClass::Quads, VboSubclass::PickColors, GL_QUADS); + drawVbos (VboClass::Lines, VboSubclass::PickColors, GL_LINES); + drawVbos (VboClass::ConditionalLines, VboSubclass::PickColors, GL_LINES); } else { @@ -428,29 +428,29 @@ { glEnable (GL_CULL_FACE); glCullFace (GL_BACK); - drawVbos (TrianglesVbo, BfcFrontColorsVboComplement, GL_TRIANGLES); - drawVbos (QuadsVbo, BfcFrontColorsVboComplement, GL_QUADS); + drawVbos (VboClass::Triangles, VboSubclass::BfcFrontColors, GL_TRIANGLES); + drawVbos (VboClass::Quads, VboSubclass::BfcFrontColors, GL_QUADS); glCullFace (GL_FRONT); - drawVbos (TrianglesVbo, BfcBackColorsVboComplement, GL_TRIANGLES); - drawVbos (QuadsVbo, BfcBackColorsVboComplement, GL_QUADS); + drawVbos (VboClass::Triangles, VboSubclass::BfcBackColors, GL_TRIANGLES); + drawVbos (VboClass::Quads, VboSubclass::BfcBackColors, GL_QUADS); glDisable (GL_CULL_FACE); } else { - ComplementVboType colors; + VboSubclass colors; if (m_config->randomColors()) - colors = RandomColorsVboComplement; + colors = VboSubclass::RandomColors; else - colors = NormalColorsVboComplement; + colors = VboSubclass::NormalColors; - drawVbos (TrianglesVbo, colors, GL_TRIANGLES); - drawVbos (QuadsVbo, colors, GL_QUADS); + drawVbos (VboClass::Triangles, colors, GL_TRIANGLES); + drawVbos (VboClass::Quads, colors, GL_QUADS); } - drawVbos (LinesVbo, NormalColorsVboComplement, GL_LINES); + drawVbos (VboClass::Lines, VboSubclass::NormalColors, GL_LINES); glEnable (GL_LINE_STIPPLE); - drawVbos (ConditionalLinesVbo, NormalColorsVboComplement, GL_LINES); + drawVbos (VboClass::ConditionalLines, VboSubclass::NormalColors, GL_LINES); glDisable (GL_LINE_STIPPLE); if (m_config->drawAxes()) @@ -479,19 +479,19 @@ // ============================================================================= // -void GLRenderer::drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type) +void GLRenderer::drawVbos (VboClass surface, VboSubclass colors, GLenum type) { // Filter this through some configuration options - if ((isOneOf (surface, QuadsVbo, TrianglesVbo) and m_config->drawSurfaces() == false) - or (surface == LinesVbo and m_config->drawEdgeLines() == false) - or (surface == ConditionalLinesVbo and m_config->drawConditionalLines() == false)) + if ((isOneOf (surface, VboClass::Quads, VboClass::Triangles) and m_config->drawSurfaces() == false) + or (surface == VboClass::Lines and m_config->drawEdgeLines() == false) + or (surface == VboClass::ConditionalLines and m_config->drawConditionalLines() == false)) { return; } - int surfaceVboNumber = m_compiler->vboNumber(surface, SurfacesVboComplement); + int surfaceVboNumber = m_compiler->vboNumber(surface, VboSubclass::Surfaces); int colorVboNumber = m_compiler->vboNumber(surface, colors); - int normalVboNumber = m_compiler->vboNumber(surface, NormalsVboComplement); + int normalVboNumber = m_compiler->vboNumber(surface, VboSubclass::Normals); m_compiler->prepareVBO(surfaceVboNumber, m_model); m_compiler->prepareVBO(colorVboNumber, m_model); m_compiler->prepareVBO(normalVboNumber, m_model); @@ -545,13 +545,13 @@ // Draw a background for the selected camera painter.setPen(thinBorderPen); painter.setBrush(QBrush {QColor {0, 128, 160, 128}}); - painter.drawRect(m_cameraIcons[camera()].hitRect); + painter.drawRect(m_cameraIcons[static_cast<int>(camera())].hitRect); // Draw the camera icons for (const CameraIcon& info : m_cameraIcons) { // Don't draw the free camera icon when we can't use the free camera - if (&info == &m_cameraIcons[FreeCamera] and not freeCameraAllowed()) + if (info.camera == Camera::Free and not freeCameraAllowed()) continue; painter.drawPixmap(info.targetRect, info.image, info.sourceRect); @@ -560,7 +560,7 @@ // Tool tips if (m_drawToolTip) { - if (not m_cameraIcons[m_toolTipCamera].targetRect.contains (m_mousePosition)) + if (not m_cameraIcons[static_cast<int>(m_toolTipCamera)].targetRect.contains (m_mousePosition)) m_drawToolTip = false; else QToolTip::showText(m_globalpos, currentCameraName()); @@ -627,7 +627,7 @@ m_panning = true; m_isCameraMoving = true; } - else if (left and camera() == FreeCamera and (xMove != 0 or yMove != 0)) + else if (left and camera() == Camera::Free and (xMove != 0 or yMove != 0)) { // Apply current rotation input to the rotation matrix // ref: https://forums.ldraw.org/thread-22006-post-24426.html#pid24426 @@ -696,10 +696,10 @@ void GLRenderer::setCamera(Camera camera) { // The edit mode may forbid the free camera. - if (freeCameraAllowed() or camera != FreeCamera) + if (freeCameraAllowed() or camera != Camera::Free) { m_camera = camera; - m_config->setCamera(int {camera}); + m_config->setCamera(static_cast<int>(camera)); } } @@ -850,8 +850,8 @@ if (camid == (Camera) -1) camid = camera(); - const CameraInfo* cam = &g_cameraInfo[camid]; - return (y) ? cam->localY : cam->localX; + const CameraInfo& cameraData = cameraInfo(camid); + return (y) ? cameraData.localY : cameraData.localX; } // ============================================================================= @@ -860,13 +860,13 @@ { switch (camera) { - case TopCamera: return tr ("Top Camera"); - case FrontCamera: return tr ("Front Camera"); - case LeftCamera: return tr ("Left Camera"); - case BottomCamera: return tr ("Bottom Camera"); - case BackCamera: return tr ("Back Camera"); - case RightCamera: return tr ("Right Camera"); - case FreeCamera: return tr ("Free Camera"); + case Camera::Top: return tr ("Top Camera"); + case Camera::Front: return tr ("Front Camera"); + case Camera::Left: return tr ("Left Camera"); + case Camera::Bottom: return tr ("Bottom Camera"); + case Camera::Back: return tr ("Back Camera"); + case Camera::Right: return tr ("Right Camera"); + case Camera::Free: return tr ("Free Camera"); default: break; } @@ -1024,7 +1024,7 @@ const CameraInfo& GLRenderer::cameraInfo (Camera camera) const { if (valueInEnum<Camera>(camera)) - return g_cameraInfo[camera]; + return g_cameraInfo[static_cast<int>(camera)]; else return g_cameraInfo[0]; } @@ -1056,19 +1056,17 @@ double& GLRenderer::panning (Axis ax) { - return (ax == X) ? m_panX[camera()] : - m_panY[camera()]; + return (ax == X) ? m_panX[static_cast<int>(camera())] : m_panY[static_cast<int>(camera())]; } double GLRenderer::panning (Axis ax) const { - return (ax == X) ? m_panX[camera()] : - m_panY[camera()]; + return (ax == X) ? m_panX[static_cast<int>(camera())] : m_panY[static_cast<int>(camera())]; } double& GLRenderer::zoom() { - return m_zoom[camera()]; + return m_zoom[static_cast<int>(camera())]; } const QGenericMatrix<4, 4, GLfloat>& GLRenderer::rotationMatrix() const
--- a/src/glRenderer.h Fri Feb 10 23:06:24 2017 +0200 +++ b/src/glRenderer.h Sun Feb 12 16:02:02 2017 +0200 @@ -44,18 +44,19 @@ bool negatedDepth; // is greater depth value closer to camera? }; -enum Camera +enum class Camera { - TopCamera, - FrontCamera, - LeftCamera, - BottomCamera, - BackCamera, - RightCamera, - FreeCamera, + Top, + Front, + Left, + Bottom, + Back, + Right, + Free, + _End }; -MAKE_ITERABLE_ENUM(Camera, TopCamera, FreeCamera) +MAKE_ITERABLE_ENUM(Camera) struct CameraIcon { @@ -177,7 +178,7 @@ GLuint m_axesColorVbo; void calcCameraIcons(); - void drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type); + void drawVbos (VboClass surface, VboSubclass colors, GLenum type); void zoomToFit(); void zoomAllToFit();
--- a/src/glShared.h Fri Feb 10 23:06:24 2017 +0200 +++ b/src/glShared.h Sun Feb 12 16:02:02 2017 +0200 @@ -36,32 +36,34 @@ } }; -enum SurfaceVboType +enum class VboClass { - LinesVbo, - TrianglesVbo, - QuadsVbo, - ConditionalLinesVbo, + Lines, + Triangles, + Quads, + ConditionalLines, + _End }; -MAKE_ITERABLE_ENUM (SurfaceVboType, LinesVbo, ConditionalLinesVbo) +MAKE_ITERABLE_ENUM(VboClass) -enum ComplementVboType +enum class VboSubclass { - SurfacesVboComplement, - NormalColorsVboComplement, - PickColorsVboComplement, - BfcFrontColorsVboComplement, - BfcBackColorsVboComplement, - RandomColorsVboComplement, - NormalsVboComplement, + Surfaces, + NormalColors, + PickColors, + BfcFrontColors, + BfcBackColors, + RandomColors, + Normals, + _End }; -MAKE_ITERABLE_ENUM (ComplementVboType, SurfacesVboComplement, NormalsVboComplement) +MAKE_ITERABLE_ENUM(VboSubclass) enum { - NumVbos = EnumLimits<SurfaceVboType>::Count * EnumLimits<ComplementVboType>::Count + NumVbos = EnumLimits<VboClass>::Count * EnumLimits<VboSubclass>::Count }; // KDevelop doesn't seem to understand some VBO stuff
--- a/src/ldDocument.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/ldDocument.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -216,7 +216,7 @@ // If the second object in the list holds the file name, update that now. LDObject* nameObject = getObject (1); - if (nameObject and nameObject->type() == OBJ_Comment) + if (nameObject and nameObject->type() == LDObjectType::Comment) { LDComment* nameComment = static_cast<LDComment*> (nameObject); @@ -269,7 +269,7 @@ // Go through all objects in the current file and reload the subfiles for (LDObject* obj : objects()) { - if (obj->type() == OBJ_SubfileReference) + if (obj->type() == LDObjectType::SubfileReference) { LDSubfileReference* reference = static_cast<LDSubfileReference*> (obj); LDDocument* fileInfo = m_documents->getDocumentByName (reference->fileInfo()->name()); @@ -282,7 +282,7 @@ // Reparse gibberish files. It could be that they are invalid because // of loading errors. Circumstances may be different now. - if (obj->type() == OBJ_Error) + if (obj->type() == LDObjectType::Error) replaceWithFromString(obj, static_cast<LDError*> (obj)->contents()); } @@ -360,7 +360,7 @@ for (LDObject* obj : model.objects()) { - if (obj->type() == OBJ_SubfileReference) + if (obj->type() == LDObjectType::SubfileReference) { print ("Warning: unable to inline %1 into %2", static_cast<LDSubfileReference*> (obj)->fileInfo()->getDisplayName(), @@ -430,7 +430,7 @@ // Got another sub-file reference, inline it if we're deep-inlining. If not, // just add it into the objects normally. Yay, recursion! - if (deep and object->type() == OBJ_SubfileReference) + if (deep and object->type() == LDObjectType::SubfileReference) static_cast<LDSubfileReference*>(object)->inlineContents(model, deep, renderinline); else model.addFromString(object->asText());
--- a/src/ldObject.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/ldObject.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -270,10 +270,10 @@ { switch (obj->type()) { - case OBJ_Line: - case OBJ_CondLine: - case OBJ_Triangle: - case OBJ_Quad: + case LDObjectType::Line: + case LDObjectType::CondLine: + case LDObjectType::Triangle: + case LDObjectType::Quad: for (int i = 0; i < obj->numVertices(); ++i) { Vertex v = obj->vertex (i); @@ -282,7 +282,7 @@ } break; - case OBJ_SubfileReference: + case LDObjectType::SubfileReference: { LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj); Matrix newMatrix = transform * ref->transformationMatrix(); @@ -320,10 +320,10 @@ LDPolygon* LDObject::getPolygon() { LDObjectType ot = type(); - int num = (ot == OBJ_Line) ? 2 - : (ot == OBJ_Triangle) ? 3 - : (ot == OBJ_Quad) ? 4 - : (ot == OBJ_CondLine) ? 5 + int num = (ot == LDObjectType::Line) ? 2 + : (ot == LDObjectType::Triangle) ? 3 + : (ot == LDObjectType::Quad) ? 4 + : (ot == LDObjectType::CondLine) ? 5 : 0; if (num == 0) @@ -419,7 +419,7 @@ { LDObject* prev = previous(); - if (prev and prev->type() == OBJ_Bfc and static_cast<LDBfc*> (prev)->statement() == BfcStatement::InvertNext) + if (prev and prev->type() == LDObjectType::Bfc and static_cast<LDBfc*> (prev)->statement() == BfcStatement::InvertNext) { ptr = static_cast<LDBfc*> (prev); return true;
--- a/src/ldObject.h Fri Feb 10 23:06:24 2017 +0200 +++ b/src/ldObject.h Sun Feb 12 16:02:02 2017 +0200 @@ -27,11 +27,11 @@ #define LDOBJ(T) \ public: \ - static constexpr LDObjectType SubclassType = OBJ_##T; \ + static constexpr LDObjectType SubclassType = LDObjectType::T; \ \ virtual LDObjectType type() const override \ { \ - return OBJ_##T; \ + return SubclassType; \ } \ \ virtual QString asText() const override; \ @@ -66,23 +66,20 @@ // enum LDObjectType { - OBJ_SubfileReference, // Object represents a sub-file reference - OBJ_Quad, // Object represents a quadrilateral - OBJ_Triangle, // Object represents a triangle - OBJ_Line, // Object represents a line - OBJ_CondLine, // Object represents a conditional line - OBJ_Bfc, // Object represents a BFC statement - OBJ_Overlay, // Object contains meta-info about an overlay image. - OBJ_Comment, // Object represents a comment - OBJ_Error, // Object is the result of failed parsing - OBJ_Empty, // Object represents an empty line - OBJ_BezierCurve, // Object represents a Bézier curve - - OBJ_NumTypes, // Amount of object types - OBJ_FirstType = OBJ_SubfileReference + SubfileReference, // Object represents a sub-file reference + Quad, // Object represents a quadrilateral + Triangle, // Object represents a triangle + Line, // Object represents a line + CondLine, // Object represents a conditional line + Bfc, // Object represents a BFC statement + Comment, // Object represents a comment + Error, // Object is the result of failed parsing + Empty, // Object represents an empty line + BezierCurve, // Object represents a Bézier curve + _End }; -MAKE_ITERABLE_ENUM (LDObjectType, OBJ_SubfileReference, OBJ_BezierCurve) +MAKE_ITERABLE_ENUM(LDObjectType) // // LDObject @@ -214,7 +211,7 @@ // // Represents a 0 BFC statement in the LDraw code. // -enum BfcStatement +enum class BfcStatement { CertifyCCW, CCW, @@ -226,9 +223,10 @@ ClipCCW, ClipCW, NoClip, + _End }; -MAKE_ITERABLE_ENUM(BfcStatement, CertifyCCW, NoClip) +MAKE_ITERABLE_ENUM(BfcStatement) class LDBfc : public LDObject {
--- a/src/linetypes/comment.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/linetypes/comment.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -27,7 +27,7 @@ LDObjectType LDComment::type() const { - return OBJ_Comment; + return LDObjectType::Comment; } QString LDComment::typeName() const
--- a/src/linetypes/comment.h Fri Feb 10 23:06:24 2017 +0200 +++ b/src/linetypes/comment.h Sun Feb 12 16:02:02 2017 +0200 @@ -25,7 +25,7 @@ class LDComment : public LDObject { public: - static constexpr LDObjectType SubclassType = OBJ_Comment; + static constexpr LDObjectType SubclassType = LDObjectType::Comment; QString asText() const override; bool isColored() const override;
--- a/src/linetypes/empty.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/linetypes/empty.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -29,7 +29,7 @@ LDObjectType LDEmpty::type() const { - return OBJ_Empty; + return LDObjectType::Empty; } QString LDEmpty::objectListText() const
--- a/src/linetypes/empty.h Fri Feb 10 23:06:24 2017 +0200 +++ b/src/linetypes/empty.h Sun Feb 12 16:02:02 2017 +0200 @@ -25,7 +25,7 @@ class LDEmpty : public LDObject { public: - static const LDObjectType SubclassType = OBJ_Empty; + static const LDObjectType SubclassType = LDObjectType::Empty; QString asText() const override; QString objectListText() const override;
--- a/src/macros.h Fri Feb 10 23:06:24 2017 +0200 +++ b/src/macros.h Sun Feb 12 16:02:02 2017 +0200 @@ -39,16 +39,16 @@ #define printValueOf(A) dprint ("value of '%1' = %2\n", #A, A) #define for_axes(AX) for (const Axis AX : std::initializer_list<const Axis> ({X, Y, Z})) -#define MAKE_ITERABLE_ENUM(T, FIRST, LAST) \ +#define MAKE_ITERABLE_ENUM(T) \ template<> \ struct EnumLimits<T> \ {\ - enum { First = FIRST, Last = LAST, End = LAST + 1, Count = End - FIRST };\ + enum { First = 0, Last = static_cast<int>(T::_End) - 1, Count = Last + 1 };\ }; \ - inline T operator++ (T& a) { a = (T) ((int) a + 1); return a; } \ - inline T operator-- (T& a) { a = (T) ((int) a - 1); return a; } \ - inline T operator++ (T& a, int) { T result = a; a = (T) ((int) a + 1); return result; } \ - inline T operator-- (T& a, int) { T result = a; a = (T) ((int) a - 1); return result; } + inline T operator++ (T& a) { a = static_cast<T>(static_cast<int>(a) + 1); return a; } \ + inline T operator-- (T& a) { a = static_cast<T>(static_cast<int>(a) - 1); return a; } \ + inline T operator++ (T& a, int) { T result = a; a = static_cast<T>(static_cast<int>(a) + 1); return result; } \ + inline T operator-- (T& a, int) { T result = a; a = static_cast<T>(static_cast<int>(a) - 1); return result; } template<typename T> struct EnumLimits {};
--- a/src/mainwindow.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/mainwindow.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -297,7 +297,7 @@ title += m_currentDocument->getDisplayName(); if (m_currentDocument->size() > 0 and - m_currentDocument->getObject(0)->type() == OBJ_Comment) + m_currentDocument->getObject(0)->type() == LDObjectType::Comment) { // Append title LDComment* comm = static_cast <LDComment*> (m_currentDocument->getObject (0)); @@ -369,7 +369,7 @@ } // Color gibberish orange on red so it stands out. - if (obj->type() == OBJ_Error) + if (obj->type() == LDObjectType::Error) { item->setBackground (QColor ("#AA0000")); item->setForeground (QColor ("#FFAA00")); @@ -616,7 +616,7 @@ for (LDObject* obj : selectedObjects()) { - if (obj->type() == OBJ_SubfileReference) + if (obj->type() == LDObjectType::SubfileReference) { hasSubfiles = true; break; @@ -625,7 +625,7 @@ QMenu* contextMenu = new QMenu; - if (single and singleObj->type() != OBJ_Empty) + if (single and singleObj->type() != LDObjectType::Empty) { contextMenu->addAction (ui.actionEdit); contextMenu->addSeparator(); @@ -662,7 +662,7 @@ contextMenu->addAction (ui.actionSubfileSelection); } - if (renderer()->camera() != FreeCamera) + if (renderer()->camera() != Camera::Free) { contextMenu->addSeparator(); contextMenu->addAction (ui.actionSetDrawDepth);
--- a/src/toolsets/algorithmtoolset.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -99,7 +99,7 @@ ui.setupUi (dlg); ui.code->setText (obj->asText()); - if (obj->type() == OBJ_Error) + if (obj->type() == LDObjectType::Error) ui.errorDescription->setText (static_cast<LDError*> (obj)->reason()); else { @@ -122,12 +122,12 @@ { const LDObjectType type = object->type(); - if (type != OBJ_Quad and type != OBJ_Triangle) + if (type != LDObjectType::Quad and type != LDObjectType::Triangle) continue; Model lines {m_documents}; - if (type == OBJ_Quad) + if (type == LDObjectType::Quad) { LDQuad* quad = static_cast<LDQuad*>(object); lines.emplace<LDLine>(quad->vertex (0), quad->vertex (1)); @@ -390,7 +390,7 @@ for (LDObject* obj : selectedObjects()) { - if (not isOneOf (obj->type(), OBJ_Line, OBJ_CondLine)) + if (not isOneOf (obj->type(), LDObjectType::Line, LDObjectType::CondLine)) continue; Model segments {m_documents}; @@ -412,7 +412,7 @@ a = (obj->vertex (0)[ax] + ((len * (i + 1)) / numSegments)); }); - if (obj->type() == OBJ_Line) + if (obj->type() == LDObjectType::Line) segments.emplace<LDLine>(v0, v1); else segments.emplace<LDCondLine>(v0, v1, obj->vertex (2), obj->vertex (3));
--- a/src/toolsets/extprogramtoolset.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/toolsets/extprogramtoolset.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -167,14 +167,14 @@ { for (LDObject* obj : objects) { - if (obj->type() == OBJ_SubfileReference) + if (obj->type() == LDObjectType::SubfileReference) { LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj); Model model {m_documents}; ref->inlineContents(model, true, false); writeObjects(model.objects().toList(), f); } - else if (obj->type() == OBJ_BezierCurve) + else if (obj->type() == LDObjectType::BezierCurve) { LDBezierCurve* curve = static_cast<LDBezierCurve*> (obj); Model model {m_documents};
--- a/src/toolsets/viewtoolset.cpp Fri Feb 10 23:06:24 2017 +0200 +++ b/src/toolsets/viewtoolset.cpp Sun Feb 12 16:02:02 2017 +0200 @@ -71,7 +71,7 @@ { types << obj->type(); - if (obj->type() == OBJ_SubfileReference) + if (obj->type() == LDObjectType::SubfileReference) subfilenames << static_cast<LDSubfileReference*> (obj)->fileInfo()->name(); } @@ -85,7 +85,7 @@ continue; // For subfiles, type check is not enough, we check the name of the document as well. - if (type == OBJ_SubfileReference + if (type == LDObjectType::SubfileReference and not subfilenames.contains (static_cast<LDSubfileReference*> (obj)->fileInfo()->name())) { continue; @@ -162,7 +162,7 @@ void ViewToolset::setDrawDepth() { - if (m_window->renderer()->camera() == FreeCamera) + if (m_window->renderer()->camera() == Camera::Free) return; bool ok;