Fri, 24 May 2013 16:43:56 +0300
Added ability to have multiple GLRenderers
src/addObjectDialog.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/file.h | file | annotate | diff | comparison | revisions | |
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/gldraw.h | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/types.h | file | annotate | diff | comparison | revisions |
--- a/src/addObjectDialog.cpp Fri May 24 15:38:23 2013 +0300 +++ b/src/addObjectDialog.cpp Fri May 24 16:43:56 2013 +0300 @@ -480,7 +480,7 @@ if (~name == 0) return; // no subfile filename - LDOpenFile* file = loadSubfile (name); + LDOpenFile* file = loadFile (name); if (!file) { critical (fmt ("Couldn't open `%s': %s", name.c (), strerror (errno))); return;
--- a/src/file.cpp Fri May 24 15:38:23 2013 +0300 +++ b/src/file.cpp Fri May 24 16:43:56 2013 +0300 @@ -318,8 +318,10 @@ LDOpenFile* load = new LDOpenFile; load->setName (path); - if (g_loadingMainFile) + if (g_loadingMainFile) { g_curfile = load; + g_win->R ()->setFile (load); + } ulong numWarnings; bool ok; @@ -404,8 +406,9 @@ // Clear the array g_loadedFiles.clear(); - g_curfile = NULL; + g_curfile = null; + g_win->R ()->setFile (null); g_win->fullRefresh (); } @@ -425,6 +428,7 @@ History::clear (); g_BBox.reset (); + g_win->R ()->setFile (f); g_win->fullRefresh (); g_win->updateTitle (); } @@ -493,6 +497,7 @@ // Rebuild the object tree view now. g_win->fullRefresh (); g_win->updateTitle (); + g_win->R ()->setFile (file); g_win->R ()->resetAngles (); History::clear (); @@ -682,7 +687,7 @@ // not loading the main file now, but the subfile bool oldLoadingMainFile = g_loadingMainFile; g_loadingMainFile = false; - LDOpenFile* load = loadSubfile (tokens[14]); + LDOpenFile* load = loadFile (tokens[14]); g_loadingMainFile = oldLoadingMainFile; // If we cannot open the file, mark it an error @@ -767,7 +772,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -LDOpenFile* loadSubfile (str fname) { +LDOpenFile* loadFile (str fname) { // Try find the subfile in the list of loaded files LDOpenFile* load = findLoadedFile (fname); @@ -798,7 +803,7 @@ if (obj->getType() == LDObject::Subfile) { // Note: ref->fileInfo is invalid right now since all subfiles were closed. LDSubfile* ref = static_cast<LDSubfile*> (obj); - LDOpenFile* fileInfo = loadSubfile (ref->fileName); + LDOpenFile* fileInfo = loadFile (ref->fileName); if (fileInfo) ref->fileInfo = fileInfo;
--- a/src/file.h Fri May 24 15:38:23 2013 +0300 +++ b/src/file.h Fri May 24 16:43:56 2013 +0300 @@ -97,7 +97,7 @@ LDObject* parseLine (str line); // Retrieves the pointer to - or loads - the given subfile. -LDOpenFile* loadSubfile (str zFile); +LDOpenFile* loadFile (str zFile); // Re-caches all subfiles. void reloadAllSubfiles ();
--- a/src/gldraw.cpp Fri May 24 15:38:23 2013 +0300 +++ b/src/gldraw.cpp Fri May 24 16:43:56 2013 +0300 @@ -21,6 +21,7 @@ #include <QMouseEvent> #include <QContextMenuEvent> #include <QInputDialog> +#include <QTimer> #include <GL/glu.h> #include "common.h" @@ -97,6 +98,8 @@ m_drawToolTip = false; m_editMode = Select; m_rectdraw = false; + setFile (null); + setDrawOnly (false); m_toolTipTimer = new QTimer (this); m_toolTipTimer->setSingleShot (true); @@ -173,9 +176,9 @@ // Set the default zoom based on the bounding box if (g_BBox.empty () == false) - m_zoom = g_BBox.size () * 6; + setZoom (g_BBox.size () * 6); else - m_zoom = 30.0f; + setZoom (30.0f); } // ============================================================================= @@ -233,7 +236,7 @@ // Make the color by the object's index color if we're picking, so we can // make the index from the color we get from the picking results. Be sure // to use the top level parent's index since inlinees don't have an index. - long i = obj->topLevelParent ()->getIndex (g_curfile); + long i = obj->topLevelParent ()->getIndex (file ()); // We should have the index now. assert (i != -1); @@ -343,8 +346,8 @@ glMatrixMode (GL_MODELVIEW); } -void GLRenderer::drawGLScene () const { - if (g_curfile == null) +void GLRenderer::drawGLScene () { + if (file () == null) return; if (gl_wireframe && !picking ()) @@ -375,16 +378,18 @@ glLoadIdentity (); glTranslatef (0.0f, 0.0f, -2.0f); - glTranslatef (m_panX, m_panY, -m_zoom); + glTranslatef (m_panX, m_panY, -zoom ()); glRotatef (m_rotX, 1.0f, 0.0f, 0.0f); glRotatef (m_rotY, 0.0f, 1.0f, 0.0f); glRotatef (m_rotZ, 0.0f, 0.0f, 1.0f); } - if (gl_colorbfc && !m_picking) { + const GL::ListType list = (!drawOnly () && m_picking) ? PickList : NormalList; + + if (gl_colorbfc && !m_picking && !drawOnly ()) { glEnable (GL_CULL_FACE); - for (LDObject* obj : g_curfile->objs ()) { + for (LDObject* obj : file ()->objs ()) { if (obj->hidden ()) continue; @@ -397,15 +402,15 @@ glDisable (GL_CULL_FACE); } else { - for (LDObject* obj : g_curfile->objs ()) { + for (LDObject* obj : file ()->objs ()) { if (obj->hidden ()) continue; - glCallList (obj->glLists[(m_picking) ? PickList : NormalList]); + glCallList (obj->glLists[list]); } } - if (gl_axes && !m_picking) + if (gl_axes && !m_picking && !drawOnly ()) glCallList (m_axeslist); glPopMatrix (); @@ -474,7 +479,9 @@ // ============================================================================= void GLRenderer::paintEvent (QPaintEvent* ev) { Q_UNUSED (ev) - m_virtWidth = m_zoom; + + makeCurrent (); + m_virtWidth = zoom (); m_virtHeight = (m_height * m_virtWidth) / m_width; initGLData (); @@ -486,6 +493,10 @@ QFontMetrics metrics = QFontMetrics (QFont ()); paint.setRenderHint (QPainter::HighQualityAntialiasing); + // If we wish to only draw the brick, stop here + if (drawOnly ()) + return; + if (m_camera != Free) { // Paint the overlay image if we have one const overlayMeta& overlay = m_overlays[m_camera]; @@ -660,12 +671,10 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::compileAllObjects () { - if (!g_curfile) { - printf ("renderer: no files loaded, cannot compile anything\n"); + if (!file ()) return; - } - for (LDObject* obj : g_curfile->objs ()) + for (LDObject* obj : file ()->objs ()) compileObject (obj); // Compile axes @@ -883,11 +892,13 @@ break; case Select: - if (!m_rangepick) - m_addpick = (m_keymods & Qt::ControlModifier); - - if (m_totalmove < 10 || m_rangepick) - pick (ev->x (), ev->y ()); + if (!drawOnly ()) { + if (!m_rangepick) + m_addpick = (m_keymods & Qt::ControlModifier); + + if (m_totalmove < 10 || m_rangepick) + pick (ev->x (), ev->y ()); + } break; } @@ -941,8 +952,8 @@ } if (ev->buttons () & Qt::MidButton) { - m_panX += 0.03f * dx * (m_zoom / 7.5f); - m_panY -= 0.03f * dy * (m_zoom / 7.5f); + m_panX += 0.03f * dx * (zoom () / 7.5f); + m_panY -= 0.03f * dy * (zoom () / 7.5f); } // Start the tool tip timer @@ -966,12 +977,14 @@ // ============================================================================= void GLRenderer::wheelEvent (QWheelEvent* ev) { - if (m_zoom > 15) - m_zoom *= (ev->delta () < 0) ? 1.2f : (1.0f / 1.2f); + makeCurrent (); + + if (zoom () > 15) + setZoom (zoom () * (ev->delta () < 0 ? 1.2f : 0.833f)); else - m_zoom += (double) ev->delta () / -100.0f; + setZoom (zoom () + ((double) ev->delta () / -100.0f)); - m_zoom = clamp<double> (m_zoom, 0.01f, 10000.0f); + setZoom (clamp<double> (zoom (), 0.01f, 10000.0f)); update (); ev->accept (); @@ -1002,6 +1015,7 @@ // ============================================================================= void GLRenderer::pick (uint mouseX, uint mouseY) { GLint viewport[4]; + makeCurrent (); // Use particularly thick lines while picking ease up selecting lines. glLineWidth (max<double> (gl_linethickness, 6.5f)); @@ -1080,7 +1094,7 @@ if (idx == 0xFFFFFF) continue; // White is background; skip - LDObject* obj = g_curfile->obj (idx); + LDObject* obj = file ()->obj (idx); // If this is an additive single pick and the object is currently selected, // we remove it from selection instead. @@ -1221,11 +1235,11 @@ } if (obj) { - g_curfile->addObject (obj); + file ()->addObject (obj); compileObject (obj); g_win->fullRefresh (); - History::addEntry (new AddHistory ({(ulong) obj->getIndex (g_curfile)}, {obj->clone ()})); + History::addEntry (new AddHistory ({(ulong) obj->getIndex (file ())}, {obj->clone ()})); } m_drawedVerts.clear (); @@ -1239,6 +1253,9 @@ deleteLists (obj); for (const GL::ListType listType : g_glListTypes) { + if (drawOnly () && listType != GL::NormalList) + continue; + GLuint list = glGenLists (1); glNewList (list, GL_COMPILE);
--- a/src/gldraw.h Fri May 24 15:38:23 2013 +0300 +++ b/src/gldraw.h Fri May 24 16:43:56 2013 +0300 @@ -20,8 +20,6 @@ #define GLDRAW_H #include <QGLWidget> -#include <qtimer.h> -#include <qdialog.h> #include "common.h" #include "ldtypes.h" @@ -30,6 +28,8 @@ class QDoubleSpinBox; class QSpinBox; class QLineEdit; +class LDOpenFile; +class QTimer; enum EditMode { Select, @@ -55,7 +55,9 @@ class GLRenderer : public QGLWidget { Q_OBJECT + PROPERTY (bool, drawOnly, setDrawOnly) PROPERTY (double, zoom, setZoom) + PROPERTY (LDOpenFile*, file, setFile) READ_PROPERTY (bool, picking) CALLBACK_PROPERTY (EditMode, editMode, setEditMode) @@ -126,7 +128,7 @@ void compileVertex (const vertex& vrt); // Compile a single vertex to a list vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point - void drawGLScene () const; // Paint the GL scene + void drawGLScene (); // Paint the GL scene void pick (uint mouseX, uint mouseY); // Perform object selection void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list
--- a/src/gui.cpp Fri May 24 15:38:23 2013 +0300 +++ b/src/gui.cpp Fri May 24 16:43:56 2013 +0300 @@ -169,6 +169,8 @@ addMenuAction ("settings"); // Settings addMenuAction ("setLDrawPath"); // Set LDraw Path menu->addSeparator (); // ------- + addMenuAction ("testpic"); // Set LDraw Path + menu->addSeparator (); // ------- addMenuAction ("exit"); // Exit // View menu
--- a/src/gui_actions.cpp Fri May 24 15:38:23 2013 +0300 +++ b/src/gui_actions.cpp Fri May 24 16:43:56 2013 +0300 @@ -449,4 +449,18 @@ if (ok) g_win->R ()->setDepthValue (depth); +} + +MAKE_ACTION (testpic, "Test picture", "", "", (0)) { + LDOpenFile* file = loadFile ("axle.dat"); + + if (!file) { + critical ("couldn't load axle.dat"); + return; + } + + GLRenderer* rend = new GLRenderer; + rend->setFile (file); + rend->setDrawOnly (true); + rend->show (); } \ No newline at end of file
--- a/src/gui_editactions.cpp Fri May 24 15:38:23 2013 +0300 +++ b/src/gui_editactions.cpp Fri May 24 16:43:56 2013 +0300 @@ -198,7 +198,7 @@ LDRadial* rad = static_cast<LDRadial*> (obj); str name = rad->makeFileName (); - LDOpenFile* file = loadSubfile (name); + LDOpenFile* file = loadFile (name); if (file == null) { fails << name; continue;
--- a/src/types.h Fri May 24 15:38:23 2013 +0300 +++ b/src/types.h Fri May 24 16:43:56 2013 +0300 @@ -211,6 +211,13 @@ m_vect.resize (size); } + template<int N> vector<T>& operator= (T vals[N]) { + for (int i = 0; i < N; ++i) + push_back (vals[i]); + + return *this; + } + private: std::vector<T> m_vect; };