Thu, 23 Feb 2017 20:18:39 +0200
print() is no longer a global function but is tied to HierarchyElement.
--- a/src/colors.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/colors.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -28,7 +28,6 @@ */ void LDColor::initColors() { - print("Initializing color information.\n"); static ColorData colors; LDColor::colorData = &colors; }
--- a/src/crashCatcher.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/crashCatcher.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -131,8 +131,6 @@ if (sigaction(signal, &sighandler, nullptr) == -1) fprint(stderr, "Couldn't set signal handler %1: %2", signal, strerror(errno)); } - - print("Crash catcher hooked to signals: %1\n", signalsToCatch); } #endif // Q_OS_UNIX
--- a/src/dialogs/colorselector.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/dialogs/colorselector.h Thu Feb 23 20:18:39 2017 +0200 @@ -20,6 +20,7 @@ #include <QDialog> #include "../main.h" #include "../colors.h" +#include "../hierarchyelement.h" class ColorSelector : public QDialog, public HierarchyElement {
--- a/src/documentloader.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/documentloader.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -118,7 +118,7 @@ // Check for parse errors and warn about them if (obj->type() == LDObjectType::Error) { - print ("Couldn't parse line #%1: %2", progress() + 1, static_cast<LDError*> (obj)->reason()); + emit parseErrorMessage(format(tr("Couldn't parse line #%1: %2"), progress() + 1, static_cast<LDError*> (obj)->reason())); ++m_warningCount; } } @@ -151,4 +151,4 @@ void DocumentLoader::abort() { m_hasAborted = true; -} \ No newline at end of file +}
--- a/src/documentloader.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/documentloader.h Thu Feb 23 20:18:39 2017 +0200 @@ -59,4 +59,5 @@ signals: void progressUpdate (int progress); void workDone(); + void parseErrorMessage(QString message); };
--- a/src/documentmanager.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/documentmanager.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -276,6 +276,7 @@ *numWarnings = 0; DocumentLoader* loader = new DocumentLoader {&model, m_loadingMainFile}; + connect(loader, SIGNAL(parseErrorMessage(QString)), this, SLOT(printParseErrorMessage(QString))); loader->read(input); loader->start(); @@ -291,6 +292,11 @@ *ok = not loader->hasAborted(); } +void DocumentManager::printParseErrorMessage(QString message) +{ + print(message); +} + LDDocument* DocumentManager::openDocument (QString path, bool search, bool implicit, LDDocument* fileToOverride, bool* aborted) {
--- a/src/documentmanager.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/documentmanager.h Thu Feb 23 20:18:39 2017 +0200 @@ -55,6 +55,8 @@ void documentClosed(LDDocument* document); private: + Q_SLOT void printParseErrorMessage(QString message); + Documents m_documents; bool m_loadingMainFile; bool m_isLoadingLogoedStuds;
--- a/src/editmodes/abstractEditMode.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/editmodes/abstractEditMode.h Thu Feb 23 20:18:39 2017 +0200 @@ -19,6 +19,7 @@ #pragma once #include "../main.h" #include "../model.h" +#include "../hierarchyelement.h" class QPainter; class Canvas;
--- a/src/format.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/format.h Thu Feb 23 20:18:39 2017 +0200 @@ -124,19 +124,6 @@ return fmtstr; } - -// From messageLog.cc - declared here so that I don't need to include messageLog.h here. -void printToLog (const QString& msg); - - -// Format and print the given args to the message log. -template<typename... Args> -void print (QString fmtstr, Args... args) -{ - formatHelper (fmtstr, args...); - printToLog (fmtstr); -} - template<typename... Args> void fprint (FILE* fp, QString fmtstr, Args... args) { @@ -151,16 +138,3 @@ formatHelper (fmtstr, args...); dev.write (fmtstr.toUtf8()); } - - -// Exactly like print() except no-op in release builds. -template<typename... Args> -#ifndef RELEASE -void dprint (QString fmtstr, Args... args) -{ - formatHelper (fmtstr, args...); - printToLog (fmtstr); -} -#else -void dprint (QString, Args...) {} -#endif
--- a/src/glcamera.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/glcamera.h Thu Feb 23 20:18:39 2017 +0200 @@ -48,7 +48,7 @@ Axis axisX() const; Axis axisY() const; Axis axisZ() const; - Vertex convert2dTo3d(const QPoint& pos2d, Grid* grid = nullptr) const; + Vertex convert2dTo3d(const QPoint& pos2d, class Grid* grid = nullptr) const; QPoint convert3dTo2d(const Vertex& pos3d) const; double depth() const; bool isAxisNegated(Axis axis) const;
--- a/src/glcompiler.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/glcompiler.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -43,7 +43,7 @@ { GL_STACK_OVERFLOW, "The operation would have caused an overflow" }, }; -void CheckGLErrorImpl (const char* file, int line) +void CheckGLErrorImpl (HierarchyElement* element, const char* file, int line) { QString errmsg; GLenum errnum = glGetError(); @@ -60,7 +60,7 @@ } } - print ("OpenGL ERROR: at %1:%2: %3", Basename (QString (file)), line, errmsg); + element->print ("OpenGL ERROR: at %1:%2: %3", Basename (QString (file)), line, errmsg); } @@ -110,7 +110,7 @@ * - polygonOwner is the LDObject from which the polygon originated. * - subclass provides context for the polygon. */ -QColor GLCompiler::getColorForPolygon(LDPolygon& polygon, LDObject* polygonOwner, VboSubclass subclass) const +QColor GLCompiler::getColorForPolygon(LDPolygon& polygon, LDObject* polygonOwner, VboSubclass subclass) { QColor color; @@ -198,7 +198,7 @@ static QSet<int> warnedColors; if (not warnedColors.contains(polygon.color)) { - print("Unknown color %1!\n", polygon.color); + print(tr("Unknown color %1!\n"), polygon.color); warnedColors.insert(polygon.color); } }
--- a/src/glcompiler.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/glcompiler.h Thu Feb 23 20:18:39 2017 +0200 @@ -38,7 +38,7 @@ GLCompiler (GLRenderer* renderer); ~GLCompiler(); - QColor getColorForPolygon (LDPolygon& poly, LDObject* topobj, VboSubclass complement) const; + QColor getColorForPolygon (LDPolygon& poly, LDObject* topobj, VboSubclass complement); QColor indexColorForID (int id) const; void initialize(); void needMerge(); @@ -68,5 +68,5 @@ GLRenderer* m_renderer; }; -#define CHECK_GL_ERROR() { CheckGLErrorImpl (__FILE__, __LINE__); } -void CheckGLErrorImpl (const char* file, int line); +#define CHECK_GL_ERROR() { CheckGLErrorImpl (this, __FILE__, __LINE__); } +void CheckGLErrorImpl (HierarchyElement* element, const char* file, int line);
--- a/src/glrenderer.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/glrenderer.h Thu Feb 23 20:18:39 2017 +0200 @@ -22,6 +22,7 @@ #include "model.h" #include "glShared.h" #include "glcamera.h" +#include "hierarchyelement.h" class GLCompiler; class MessageManager;
--- a/src/hierarchyelement.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/hierarchyelement.h Thu Feb 23 20:18:39 2017 +0200 @@ -20,14 +20,16 @@ #include <QObject> #include "main.h" #include "configuration.h" +#include "messageLog.h" +#include "mainwindow.h" -class MainWindow; class GuiUtilities; class LDDocument; class DocumentManager; class PrimitiveManager; class Grid; class MathFunctions; +class MainWindow; // // Objects that are to take part in the MainWindow's hierarchy multiple-inherit from this class to get a pointer back @@ -48,6 +50,14 @@ // Utility functions QString preferredLicenseText() const; + // Format and print the given args to the message log. + template<typename... Args> + void print(QString formatString, Args... args) + { + formatHelper(formatString, args...); + m_window->addMessage(formatString); + } + protected: MainWindow* m_window; DocumentManager* m_documents;
--- a/src/lddocument.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/lddocument.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -301,7 +301,7 @@ #ifdef DEBUG if (not isFrozen()) - dprint ("Inserted object #%1 (%2) at %3\n", obj->id(), obj->typeName(), pos); + print("Inserted object #%1 (%2) at %3\n", obj->id(), obj->typeName(), pos); #endif }
--- a/src/lddocument.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/lddocument.h Thu Feb 23 20:18:39 2017 +0200 @@ -23,6 +23,7 @@ #include "editHistory.h" #include "glShared.h" #include "model.h" +#include "hierarchyelement.h" struct LDGLData; class DocumentManager;
--- a/src/main.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/main.h Thu Feb 23 20:18:39 2017 +0200 @@ -31,5 +31,4 @@ #include "macros.h" #include "version.h" #include "format.h" -#include "hierarchyelement.h" #include "configuration.h"
--- a/src/mainwindow.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/mainwindow.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -768,9 +768,12 @@ return false; } -void MainWindow::addMessage (QString msg) +void MainWindow::addMessage(QString message) { - messageLog()->addLine (msg); + messageLog()->addLine(message); + + // Also print it to stdout + fprint(stdout, "%1\n", message); } /*
--- a/src/mainwindow.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/mainwindow.h Thu Feb 23 20:18:39 2017 +0200 @@ -36,6 +36,8 @@ class PrimitiveManager; class Grid; class MathFunctions; +class DocumentManager; +class LDDocument; class ColorToolbarItem { @@ -118,6 +120,13 @@ static QPixmap getIcon(QString iconName); static class QSettings* makeSettings(QObject* parent = nullptr); + template<typename... Args> + void print(QString formatString, Args... args) + { + formatHelper(formatString, args...); + addMessage(formatString); + } + signals: void gridChanged();
--- a/src/mathfunctions.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/mathfunctions.h Thu Feb 23 20:18:39 2017 +0200 @@ -18,6 +18,7 @@ #pragma once #include "main.h" +#include "hierarchyelement.h" enum RotationPoint
--- a/src/messageLog.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/messageLog.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -117,17 +117,3 @@ { return m_lines; } - -// ============================================================================= -// -void printToLog (const QString& msg) -{ - for (QString& a : msg.split ("\n", QString::SkipEmptyParts)) - { - if (g_win) - g_win->addMessage (a); - - // Also print it to stdout - fprint (stdout, "%1\n", a); - } -}
--- a/src/model.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/model.h Thu Feb 23 20:18:39 2017 +0200 @@ -28,7 +28,7 @@ Q_OBJECT public: - Model(DocumentManager* manager); + Model(class DocumentManager* manager); Model(const Model& other) = delete; ~Model(); @@ -53,7 +53,7 @@ QVector<LDObject*>::iterator begin(); QVector<LDObject*>::iterator end(); bool isEmpty() const; - DocumentManager* documentManager() const; + class DocumentManager* documentManager() const; LDObject* insertFromString(int position, QString line); LDObject* addFromString(QString line); LDObject* replaceWithFromString(LDObject* object, QString line); @@ -69,7 +69,7 @@ virtual LDObject* withdrawAt(int position); QVector<LDObject*> _objects; - DocumentManager* _manager; + class DocumentManager* _manager; mutable int _triangleCount = 0; mutable bool _needsTriangleRecount; }; @@ -154,4 +154,4 @@ object->setColor(object->defaultColor()); return object; -} \ No newline at end of file +}
--- a/src/primitives.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/primitives.h Thu Feb 23 20:18:39 2017 +0200 @@ -23,6 +23,7 @@ #include <QDirIterator> #include "main.h" #include "model.h" +#include "hierarchyelement.h" class LDDocument; class Ui_GeneratePrimitiveDialog;
--- a/src/toolsets/toolset.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/toolsets/toolset.h Thu Feb 23 20:18:39 2017 +0200 @@ -19,6 +19,7 @@ #pragma once #include <QObject> #include "../main.h" +#include "../hierarchyelement.h" class MainWindow;
--- a/src/types/matrix.cpp Thu Feb 23 20:06:22 2017 +0200 +++ b/src/types/matrix.cpp Thu Feb 23 20:18:39 2017 +0200 @@ -52,20 +52,6 @@ } /* - * Prints the matrix out. - */ -void Matrix::dump() const -{ - for (int i = 0; i < 3; ++i) - { - for (int j = 0; j < 3; ++j) - print ("%1\t", m_values[i * 3 + j]); - - print ("\n"); - } -} - -/* * Returns a string representation of the matrix */ QString Matrix::toString() const
--- a/src/types/matrix.h Thu Feb 23 20:06:22 2017 +0200 +++ b/src/types/matrix.h Thu Feb 23 20:18:39 2017 +0200 @@ -36,7 +36,6 @@ double* begin(); const double* begin() const; double determinant() const; - void dump() const; double* end(); const double* end() const; Matrix multiply(const Matrix& other) const;