# HG changeset patch # User Teemu Piippo # Date 1579434787 -7200 # Node ID 3387a84ddaba97a7f82c2b428f19a2d7884bf23e # Parent 6da867fa5429d288aadcc0f26153db9f11eaae58 fixed a pile of nonsense that caused subfiles to go haywire diff -r 6da867fa5429 -r 3387a84ddaba locale/fi.ts --- a/locale/fi.ts Sun Jan 19 02:54:48 2020 +0200 +++ b/locale/fi.ts Sun Jan 19 13:53:07 2020 +0200 @@ -189,7 +189,7 @@ PartRenderer - + Rendering error diff -r 6da867fa5429 -r 3387a84ddaba src/documentmanager.cpp --- a/src/documentmanager.cpp Sun Jan 19 02:54:48 2020 +0200 +++ b/src/documentmanager.cpp Sun Jan 19 13:53:07 2020 +0200 @@ -97,12 +97,13 @@ void DocumentManager::loadDependenciesForModel( const QString& modelName, + const QString& path, const LibraryManager& libraries, QTextStream& errorStream) { QStringList missing; QStringList processed; - loadDependenciesForModel(modelName, libraries, missing, processed, errorStream); + loadDependenciesForModel(modelName, path, libraries, missing, processed, errorStream); if (not missing.empty()) { missing.sort(Qt::CaseInsensitive); @@ -112,8 +113,23 @@ } } +static QString findFile(QString referenceName, const QString& path, const LibraryManager& libraries) +{ + // Try to find the file in the same place as the model itself + referenceName.replace("\\", "/"); + const QDir dir = QFileInfo{path}.dir(); + QString referencedFilePath = dir.filePath(referenceName); + if (not QFileInfo{referencedFilePath}.exists()) + { + // Look for it in the libraries + referencedFilePath = libraries.findFile(referenceName); + } + return referencedFilePath; +} + void DocumentManager::loadDependenciesForModel( const QString& modelName, + const QString &path, const LibraryManager& libraries, QStringList& missing, QStringList& processed, @@ -134,24 +150,24 @@ { try { - const QString path = libraries.findFile(referenceName); - if (path.isEmpty()) + const QString referencedFilePath = findFile(referenceName, path, libraries); + if (referencedFilePath.isEmpty()) { throw LoadingError{utility::format("'%1' was not found.", referenceName)}; } QString errorString; QTextStream localErrorStream{&errorString}; - QString resultName = this->openModel(path, localErrorStream); + QString resultName = this->openModel(referencedFilePath, localErrorStream); if (resultName.isEmpty()) { throw LoadingError{utility::format( "could not load '%1': %2", - path, + referencedFilePath, errorString)}; } if (not processed.contains(referenceName)) { - loadDependenciesForModel(referenceName, libraries, missing, processed, errorStream); + loadDependenciesForModel(referenceName, path, libraries, missing, processed, errorStream); } } catch(const LoadingError& error) diff -r 6da867fa5429 -r 3387a84ddaba src/documentmanager.h --- a/src/documentmanager.h Sun Jan 19 02:54:48 2020 +0200 +++ b/src/documentmanager.h Sun Jan 19 13:53:07 2020 +0200 @@ -13,12 +13,14 @@ QString openModel(const QString& path, QTextStream& errorStream); QString makeNewModelName(); void loadDependenciesForModel(const QString& modelName, + const QString& path, const LibraryManager& libraries, QTextStream& errorStream); private: int untitledNameCounter = 0; std::map openModels; void loadDependenciesForModel(const QString& modelName, + const QString& path, const LibraryManager& libraries, QStringList& missing, QStringList& processed, diff -r 6da867fa5429 -r 3387a84ddaba src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Sun Jan 19 02:54:48 2020 +0200 +++ b/src/gl/partrenderer.cpp Sun Jan 19 13:53:07 2020 +0200 @@ -110,17 +110,12 @@ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break; } - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glMatrixMode(GL_MODELVIEW); - // clear the drawing buffer. glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); - // clear the identity matrix. glLoadIdentity(); - // traslate the draw by z = -4.0 - // Note this when you decrease z like -8.0 the drawing will looks far , or smaller. glTranslatef(0.0, 0.0, -4.5 * this->compiler->modelDistance()); glMultMatrixf(padMatrix(this->rotation.toRotationMatrix()).constData()); xyz(glTranslatef, -this->compiler->modelCenter()); @@ -145,7 +140,6 @@ glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); - //glFlush(); const GLenum glError = this->glGetError(); if (glError != GL_NO_ERROR) { diff -r 6da867fa5429 -r 3387a84ddaba src/linetypes/subfilereference.cpp --- a/src/linetypes/subfilereference.cpp Sun Jan 19 02:54:48 2020 +0200 +++ b/src/linetypes/subfilereference.cpp Sun Jan 19 13:53:07 2020 +0200 @@ -57,9 +57,9 @@ polygons.reserve(polygons.size() + modelPolygons.size()); for (gl::Polygon polygon : modelPolygons) { - for (int i = 0; i < polygon.numPolygonVertices(); i += 1) + for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) { - polygon.vertices[i] = math::transform(polygon.vertices[1], this->transformation); + polygon.vertices[i] = math::transform(polygon.vertices[i], this->transformation); } if (polygon.color == colors::main) { diff -r 6da867fa5429 -r 3387a84ddaba src/mainwindow.cpp --- a/src/mainwindow.cpp Sun Jan 19 02:54:48 2020 +0200 +++ b/src/mainwindow.cpp Sun Jan 19 13:53:07 2020 +0200 @@ -57,7 +57,7 @@ QString modelName = this->documents.openModel(path, errorStream); if (not modelName.isEmpty()) { - this->documents.loadDependenciesForModel(modelName, this->libraries, errorStream); + this->documents.loadDependenciesForModel(modelName, path, this->libraries, errorStream); if (not errorString.isEmpty()) { QMessageBox::warning( diff -r 6da867fa5429 -r 3387a84ddaba src/parser.cpp --- a/src/parser.cpp Sun Jan 19 02:54:48 2020 +0200 +++ b/src/parser.cpp Sun Jan 19 13:53:07 2020 +0200 @@ -339,8 +339,8 @@ { Q_UNUSED(line) constexpr int colorPosition = 1; - constexpr int transformPosition = 2; // 2..10 - constexpr int positionPosition = 11; // 11..13 + constexpr int positionPosition = 2; // 2..4 + constexpr int transformPosition = 5; // 5..13 constexpr int namePosition = 14; if (tokens.size() != 15) { diff -r 6da867fa5429 -r 3387a84ddaba src/types/boundingbox.cpp --- a/src/types/boundingbox.cpp Sun Jan 19 02:54:48 2020 +0200 +++ b/src/types/boundingbox.cpp Sun Jan 19 13:53:07 2020 +0200 @@ -41,11 +41,11 @@ { if (box != emptyBoundingBox) { - double dx = box.minimum.x - box.maximum.x; - double dy = box.minimum.y - box.maximum.y; - double dz = box.minimum.z - box.maximum.z; - double size = std::max(std::max(dx, dy), dz); - return std::max(std::abs(size / 2.0), 1.0); + const double dx = std::abs(box.minimum.x - box.maximum.x); + const double dy = std::abs(box.minimum.y - box.maximum.y); + const double dz = std::abs(box.minimum.z - box.maximum.z); + const double size = std::max(std::max(dx, dy), dz); + return std::max(size / 2.0, 1.0); } else {