Thu, 09 Feb 2017 00:43:30 +0200
LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
src/editmodes/abstractEditMode.cpp | file | annotate | diff | comparison | revisions | |
src/editmodes/selectMode.cpp | file | annotate | diff | comparison | revisions | |
src/glCompiler.cpp | file | annotate | diff | comparison | revisions | |
src/glCompiler.h | file | annotate | diff | comparison | revisions | |
src/glRenderer.cpp | file | annotate | diff | comparison | revisions | |
src/glRenderer.h | file | annotate | diff | comparison | revisions | |
src/ldDocument.cpp | file | annotate | diff | comparison | revisions | |
src/ldDocument.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions |
--- a/src/editmodes/abstractEditMode.cpp Thu Feb 09 00:32:24 2017 +0200 +++ b/src/editmodes/abstractEditMode.cpp Thu Feb 09 00:43:30 2017 +0200 @@ -27,6 +27,7 @@ #include "linePathMode.h" #include "curvemode.h" #include "../mainwindow.h" +#include "../ldDocument.h" #include "../glRenderer.h" #include "../miscallenous.h" #include "../grid.h" @@ -121,7 +122,7 @@ Vertex cursorPosition = renderer()->convert2dTo3d(data.ev->pos(), false); QPoint cursorPosition2D = data.ev->pos(); const Axis depthAxis = renderer()->getRelativeZ(); - QList<Vertex> vertices = renderer()->document()->inlineVertices().toList(); + QList<Vertex> vertices = currentDocument()->inlineVertices().toList(); // Sort the vertices in order of distance to camera std::sort(vertices.begin(), vertices.end(), [&](const Vertex& a, const Vertex& b) -> bool @@ -196,7 +197,7 @@ if (countof(model) > 0) { - renderer()->document()->merge(model, position); + renderer()->model()->merge(model, position); m_window->refresh(); m_window->endAction(); }
--- a/src/editmodes/selectMode.cpp Thu Feb 09 00:32:24 2017 +0200 +++ b/src/editmodes/selectMode.cpp Thu Feb 09 00:43:30 2017 +0200 @@ -20,7 +20,7 @@ #include "selectMode.h" #include "../glRenderer.h" #include "../mainwindow.h" -#include "../glRenderer.h" +#include "../ldDocument.h" SelectMode::SelectMode (GLRenderer* renderer) : Super (renderer), @@ -116,7 +116,7 @@ if (ev->buttons() & Qt::LeftButton) { - renderer()->document()->clearSelection(); + currentDocument()->clearSelection(); LDObject* obj = renderer()->pickOneObject (ev->x(), ev->y()); if (obj)
--- a/src/glCompiler.cpp Thu Feb 09 00:32:24 2017 +0200 +++ b/src/glCompiler.cpp Thu Feb 09 00:43:30 2017 +0200 @@ -216,11 +216,11 @@ } -void GLCompiler::compileDocument (LDDocument* doc) +void GLCompiler::compileModel (Model* model) { - if (doc) + if (model) { - for (LDObject* obj : doc->objects()) + for (LDObject* obj : model->objects()) compileObject (obj); } } @@ -235,7 +235,7 @@ } -void GLCompiler::prepareVBO (int vbonum) +void GLCompiler::prepareVBO (int vbonum, Model* model) { // Compile anything that still awaits it compileStaged(); @@ -253,7 +253,7 @@ continue; } - if (it.key()->model() == currentDocument() and not it.key()->isHidden()) + if (it.key()->model() == model and not it.key()->isHidden()) vbodata += it->data[vbonum]; ++it;
--- a/src/glCompiler.h Thu Feb 09 00:32:24 2017 +0200 +++ b/src/glCompiler.h Thu Feb 09 00:43:30 2017 +0200 @@ -36,13 +36,13 @@ GLCompiler (GLRenderer* renderer); ~GLCompiler(); - void compileDocument (LDDocument* doc); + void compileModel (Model* model); void dropObjectInfo (LDObject* obj); QColor getColorForPolygon (LDPolygon& poly, LDObject* topobj, ComplementVboType complement) const; QColor indexColorForID (int id) const; void initialize(); void needMerge(); - void prepareVBO (int vbonum); + void prepareVBO (int vbonum, Model* model); void setRenderer (GLRenderer* compiler); void stageForCompilation (LDObject* obj); void unstage (LDObject* obj);
--- a/src/glRenderer.cpp Thu Feb 09 00:32:24 2017 +0200 +++ b/src/glRenderer.cpp Thu Feb 09 00:43:30 2017 +0200 @@ -67,10 +67,10 @@ // ============================================================================= // -GLRenderer::GLRenderer(LDDocument* document, QWidget* parent) : +GLRenderer::GLRenderer(Model* model, QWidget* parent) : QGLWidget {parent}, HierarchyElement {parent}, - m_document {document} + m_model {model} { m_camera = (Camera) m_config->camera(); m_currentEditMode = AbstractEditMode::createByType (this, EditModeType::Select); @@ -82,14 +82,8 @@ setAcceptDrops (true); connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); initOverlaysFromObjects(); - - if (not currentDocumentData().init) - { - resetAllAngles(); - currentDocumentData().init = true; - } - - currentDocumentData().needZoomToFit = true; + resetAllAngles(); + m_needZoomToFit = true; // Init camera icons for (Camera camera : iterateEnum<Camera>()) @@ -183,9 +177,9 @@ m_isDrawOnly = value; } -LDDocument* GLRenderer::document() const +Model* GLRenderer::model() const { - return m_document; + return m_model; } GLCompiler* GLRenderer::compiler() const @@ -202,8 +196,7 @@ // void GLRenderer::needZoomToFit() { - if (document()) - currentDocumentData().needZoomToFit = true; + m_needZoomToFit = true; } // ============================================================================= @@ -218,7 +211,7 @@ glLoadIdentity(); glRotatef(30, 1, 0, 0); glRotatef(330, 0, 1, 0); - glGetFloatv(GL_MODELVIEW_MATRIX, currentDocumentData().rotationMatrix.data()); + glGetFloatv(GL_MODELVIEW_MATRIX, m_rotationMatrix.data()); glPopMatrix(); } panning(X) = panning(Y) = 0.0f; @@ -343,7 +336,7 @@ { if (m_initialized) { - compiler()->compileDocument (currentDocument()); + compiler()->compileModel (currentDocument()); refresh(); } } @@ -366,12 +359,9 @@ // void GLRenderer::drawGLScene() { - if (document() == nullptr) - return; - - if (currentDocumentData().needZoomToFit) + if (m_needZoomToFit) { - currentDocumentData().needZoomToFit = false; + m_needZoomToFit = false; zoomAllToFit(); } @@ -411,7 +401,7 @@ glLoadIdentity(); glTranslatef(0.0f, 0.0f, -2.0f); glTranslatef(panning (X), panning (Y), -zoom()); - glMultMatrixf(currentDocumentData().rotationMatrix.constData()); + glMultMatrixf(m_rotationMatrix.constData()); } glEnableClientState (GL_VERTEX_ARRAY); @@ -490,8 +480,8 @@ int surfaceVboNumber = m_compiler->vboNumber(surface, SurfacesVboComplement); int colorVboNumber = m_compiler->vboNumber(surface, colors); - m_compiler->prepareVBO(surfaceVboNumber); - m_compiler->prepareVBO(colorVboNumber); + m_compiler->prepareVBO(surfaceVboNumber, currentDocument()); + m_compiler->prepareVBO(colorVboNumber, currentDocument()); GLuint surfaceVbo = m_compiler->vbo(surfaceVboNumber); GLuint colorVbo = m_compiler->vbo(colorVboNumber); GLsizei count = m_compiler->vboSize(surfaceVboNumber) / 3; @@ -607,7 +597,7 @@ #ifndef RELEASE { QString text = format("Rotation: %1\nPanning: (%2, %3), Zoom: %4", - currentDocumentData().rotationMatrix, panning(X), panning(Y), zoom()); + m_rotationMatrix, panning(X), panning(Y), zoom()); QRect textSize = metrics.boundingRect(0, 0, m_width, m_height, Qt::AlignCenter, text); painter.setPen(textPen()); painter.drawText((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(), @@ -618,12 +608,12 @@ if (camera() != FreeCamera) { // Paint the overlay image if we have one - const LDGLOverlay& overlay = currentDocumentData().overlays[camera()]; + const LDGLOverlay& overlay = m_overlays[camera()]; if (overlay.image) { - QPoint v0 = convert3dTo2d(currentDocumentData().overlays[camera()].v0); - QPoint v1 = convert3dTo2d(currentDocumentData().overlays[camera()].v1); + QPoint v0 = convert3dTo2d(m_overlays[camera()].v0); + QPoint v1 = convert3dTo2d(m_overlays[camera()].v1); QRect targetRect = {v0.x(), v0.y(), qAbs(v1.x() - v0.x()), qAbs(v1.y() - v0.y())}; QRect sourceRect = {0, 0, overlay.image->width(), overlay.image->height()}; painter.drawImage(targetRect, *overlay.image, sourceRect); @@ -664,10 +654,10 @@ painter.drawText(QPoint {margin, height() - margin - metrics.descent()}, currentCameraName()); // Also render triangle count. - if (m_document) + if (m_model) { QPoint renderPoint = {margin, height() - margin - metrics.height() - metrics.descent()}; - painter.drawText(renderPoint, format("△ %1", m_document->triangleCount())); + painter.drawText(renderPoint, format("△ %1", m_model->triangleCount())); } } @@ -803,8 +793,8 @@ glLoadIdentity(); // 0.6 is an arbitrary rotation sensitivity scalar glRotatef(0.6 * hypot(xMove, yMove), yMove, xMove, 0); - glMultMatrixf(currentDocumentData().rotationMatrix.constData()); - glGetFloatv(GL_MODELVIEW_MATRIX, currentDocumentData().rotationMatrix.data()); + glMultMatrixf(m_rotationMatrix.constData()); + glGetFloatv(GL_MODELVIEW_MATRIX, m_rotationMatrix.data()); glPopMatrix(); m_isCameraMoving = true; } @@ -961,14 +951,14 @@ // Select all objects that we now have selected that were not selected before. for (LDObject* object : newSelection - priorSelection) { - m_document->addToSelection(object); + currentDocument()->addToSelection(object); compileObject(object); } // Likewise, deselect whatever was selected that isn't anymore. for (LDObject* object : priorSelection - newSelection) { - m_document->removeFromSelection(object); + currentDocument()->removeFromSelection(object); compileObject(object); } @@ -1131,7 +1121,7 @@ if (image->isNull()) { Critical (tr ("Failed to load overlay image!")); - currentDocumentData().overlays[camera].invalid = true; + m_overlays[camera].invalid = true; delete image; return false; } @@ -1181,7 +1171,7 @@ if (camera() == FreeCamera) return; - LDGLOverlay& info = currentDocumentData().overlays[camera()]; + LDGLOverlay& info = m_overlays[camera()]; delete info.image; info.image = nullptr; @@ -1193,7 +1183,7 @@ void GLRenderer::setDepthValue (double depth) { if (camera() < FreeCamera) - currentDocumentData().depthValues[camera()] = depth; + m_depthValues[camera()] = depth; } // ============================================================================= @@ -1201,7 +1191,7 @@ double GLRenderer::getDepthValue() const { if (camera() < FreeCamera) - return currentDocumentData().depthValues[camera()]; + return m_depthValues[camera()]; else return 0.0; } @@ -1234,7 +1224,7 @@ // LDGLOverlay& GLRenderer::getOverlay (int newcam) { - return currentDocumentData().overlays[newcam]; + return m_overlays[newcam]; } // ============================================================================= @@ -1250,7 +1240,7 @@ { zoom() = 30.0f; - if (document() == nullptr or m_width == -1 or m_height == -1) + if (model() == nullptr or m_width == -1 or m_height == -1) return; bool lastfilled = false; @@ -1353,7 +1343,7 @@ // LDOverlay* GLRenderer::findOverlayObject (Camera cam) { - for (LDObject* obj : document()->objects()) + for (LDObject* obj : model()->objects()) { LDOverlay* overlay = dynamic_cast<LDOverlay*> (obj); @@ -1375,7 +1365,7 @@ if (camera == FreeCamera) continue; - LDGLOverlay& meta = currentDocumentData().overlays[camera]; + LDGLOverlay& meta = m_overlays[camera]; LDOverlay* overlay = findOverlayObject (camera); if (overlay == nullptr and meta.image) @@ -1404,7 +1394,7 @@ if (camera == FreeCamera) continue; - LDGLOverlay& meta = currentDocumentData().overlays[camera]; + LDGLOverlay& meta = m_overlays[camera]; LDOverlay* overlayObject = findOverlayObject (camera); if (meta.image == nullptr and overlayObject) @@ -1413,11 +1403,11 @@ LDObject* nextobj = overlayObject->next(); if (nextobj and nextobj->type() == OBJ_Empty) - document()->remove(nextobj); + model()->remove(nextobj); // If the overlay object was there and the overlay itself is // not, remove the object. - document()->remove(overlayObject); + model()->remove(overlayObject); overlayObject = nullptr; } else if (meta.image and overlayObject == nullptr) @@ -1435,9 +1425,9 @@ int lastOverlayPosition = -1; bool found = false; - for (i = 0; i < document()->size(); ++i) + for (i = 0; i < model()->size(); ++i) { - LDObject* object = document()->getObject (i); + LDObject* object = model()->getObject (i); if (object->isScemantic()) { @@ -1451,14 +1441,14 @@ if (lastOverlayPosition != -1) { - overlayObject = document()->emplaceAt<LDOverlay>(lastOverlayPosition + 1); + overlayObject = model()->emplaceAt<LDOverlay>(lastOverlayPosition + 1); } else { - overlayObject = document()->emplaceAt<LDOverlay>(i); + overlayObject = model()->emplaceAt<LDOverlay>(i); if (found) - document()->emplaceAt<LDEmpty>(i + 1); + model()->emplaceAt<LDEmpty>(i + 1); } } @@ -1590,26 +1580,21 @@ return m_camera; } -LDGLData& GLRenderer::currentDocumentData() const -{ - return *document()->glData(); -} - double& GLRenderer::panning (Axis ax) { - return (ax == X) ? currentDocumentData().panX[camera()] : - currentDocumentData().panY[camera()]; + return (ax == X) ? m_panX[camera()] : + m_panY[camera()]; } double GLRenderer::panning (Axis ax) const { - return (ax == X) ? currentDocumentData().panX[camera()] : - currentDocumentData().panY[camera()]; + return (ax == X) ? m_panX[camera()] : + m_panY[camera()]; } double& GLRenderer::zoom() { - return currentDocumentData().zoom[camera()]; + return m_zoom[camera()]; } @@ -1617,10 +1602,6 @@ // --------------------------------------------------------------------------------------------------------------------- // - -LDGLOverlay::LDGLOverlay() : - image(nullptr) {} - LDGLOverlay::~LDGLOverlay() { delete image;
--- a/src/glRenderer.h Thu Feb 09 00:32:24 2017 +0200 +++ b/src/glRenderer.h Thu Feb 09 00:43:30 2017 +0200 @@ -19,9 +19,7 @@ #pragma once #include <QGLWidget> #include "main.h" -#include "macros.h" -#include "ldObject.h" -#include "ldDocument.h" +#include "model.h" #include "glShared.h" #include "editmodes/abstractEditMode.h" @@ -50,7 +48,6 @@ // struct LDGLOverlay { - LDGLOverlay(); ~LDGLOverlay(); Vertex v0, @@ -60,42 +57,8 @@ double width, height; QString fileName; - QImage* image; - bool invalid; -}; - -// -// Document-specific data -// -struct LDGLData -{ - QGenericMatrix<4, 4, GLfloat> rotationMatrix; - double panX[7]; - double panY[7]; - double zoom[7]; - double depthValues[6]; - LDGLOverlay overlays[6]; - bool init; - bool needZoomToFit; - - LDGLData() : - init (false), - needZoomToFit (true) - { - for (int i = 0; i < 7; ++i) - { - if (i < 6) - { - overlays[i].image = nullptr; - overlays[i].invalid = false; - depthValues[i] = 0.0f; - } - - zoom[i] = 30.0; - panX[i] = 0.0; - panY[i] = 0.0; - } - } + QImage* image = nullptr; + bool invalid = false; }; enum Camera @@ -126,7 +89,7 @@ Q_OBJECT public: - GLRenderer(LDDocument* document, QWidget* parent = nullptr); + GLRenderer(Model* model, QWidget* parent = nullptr); ~GLRenderer(); Camera camera() const; @@ -141,7 +104,7 @@ QString currentCameraName() const; EditModeType currentEditModeType() const; int depthNegateFactor() const; - LDDocument* document() const; + Model* model() const; void drawPoint(QPainter& painter, QPointF pos, QColor color = QColor (64, 192, 0)) const; void drawBlipCoordinates(QPainter& painter, const Vertex& pos3d); void drawBlipCoordinates(QPainter& painter, const Vertex& pos3d, QPointF pos); @@ -201,7 +164,7 @@ void wheelEvent(QWheelEvent* ev); private: - LDDocument* m_document = nullptr; + Model* const m_model; GLCompiler* m_compiler; LDObject* m_objectAtCursor = nullptr; CameraIcon m_cameraIcons[7]; @@ -211,6 +174,12 @@ Vertex m_position3D; double m_virtualWidth; double m_virtualHeight; + QGenericMatrix<4, 4, GLfloat> m_rotationMatrix; + double m_panX[7] = {0}; + double m_panY[7] = {0}; + double m_zoom[7] = {30}; + double m_depthValues[6]; + LDGLOverlay m_overlays[6]; bool m_useDarkBackground = false; bool m_drawToolTip = false; bool m_takingScreenCapture = false; @@ -219,6 +188,7 @@ bool m_isDrawOnly = false; bool m_isDrawingSelectionScene = false; bool m_isCameraMoving = false; + bool m_needZoomToFit = true; QPoint m_mousePosition; QPoint m_globalpos; QPointF m_mousePositionF; @@ -235,7 +205,6 @@ GLuint m_axesColorVbo; void calcCameraIcons(); - LDGLData& currentDocumentData() const; void drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type); LDOverlay* findOverlayObject (Camera cam); double& panning (Axis ax);
--- a/src/ldDocument.cpp Thu Feb 09 00:32:24 2017 +0200 +++ b/src/ldDocument.cpp Thu Feb 09 00:43:30 2017 +0200 @@ -34,14 +34,12 @@ m_flags(IsFrozen | VerticesOutdated | NeedsVertexMerge | NeedsRecache), m_savePosition(-1), m_tabIndex(-1), - m_gldata (new LDGLData), m_manager (parent) {} LDDocument::~LDDocument() { m_flags |= IsBeingDestroyed; delete m_history; - delete m_gldata; } QString LDDocument::name() const @@ -151,11 +149,6 @@ } } -LDGLData* LDDocument::glData() -{ - return m_gldata; -} - // ============================================================================= // // Performs safety checks. Do this before closing any files!
--- a/src/ldDocument.h Thu Feb 09 00:32:24 2017 +0200 +++ b/src/ldDocument.h Thu Feb 09 00:43:30 2017 +0200 @@ -68,7 +68,6 @@ QString fullPath(); QString getDisplayName(); const QSet<LDObject*>& getSelection() const; - LDGLData* glData(); bool hasUnsavedChanges() const; EditHistory* history() const; void initializeCachedData(); @@ -121,7 +120,6 @@ QMap<LDObject*, QSet<Vertex>> m_objectVertices; QSet<Vertex> m_vertices; QSet<LDObject*> m_selection; - LDGLData* m_gldata; DocumentManager* m_manager; DEFINE_FLAG_ACCESS_METHODS(m_flags)
--- a/src/mainwindow.cpp Thu Feb 09 00:32:24 2017 +0200 +++ b/src/mainwindow.cpp Thu Feb 09 00:43:30 2017 +0200 @@ -1149,7 +1149,7 @@ print ("Opened %1", document->name()); // Cache files are not compiled by the GL renderer. Now that this file is open for editing, it needs to be compiled. - getRendererForDocument(document)->compiler()->compileDocument(document); + getRendererForDocument(document)->compiler()->compileModel(document); updateDocumentList(); } }