Sun, 18 Mar 2018 12:33:29 +0200
fixed infinite recursion and integrated the subfilereference editor
--- a/src/dialogs/subfilereferenceeditor.cpp Sun Mar 18 12:00:39 2018 +0200 +++ b/src/dialogs/subfilereferenceeditor.cpp Sun Mar 18 12:33:29 2018 +0200 @@ -3,6 +3,7 @@ #include "../linetypes/modelobject.h" #include "../primitives.h" #include "../guiutilities.h" +#include "../dialogs/colorselector.h" SubfileReferenceEditor::SubfileReferenceEditor(LDSubfileReference* reference, QWidget* parent) : QDialog {parent}, @@ -15,7 +16,17 @@ this->ui.positionX->setValue(reference->position().x()); this->ui.positionY->setValue(reference->position().y()); this->ui.positionZ->setValue(reference->position().z()); - ::setupColorButton(parent, this->ui.colorButton, &this->color); + + connect( + this->ui.colorButton, + &QPushButton::clicked, + [&]() + { + if (ColorSelector::selectColor(this, this->color, this->color)) + ::setColorButton(this->ui.colorButton, this->color); + } + ); + for (int i : {0, 1, 2}) for (int j : {0, 1, 2}) {
--- a/src/documentmanager.cpp Sun Mar 18 12:00:39 2018 +0200 +++ b/src/documentmanager.cpp Sun Mar 18 12:33:29 2018 +0200 @@ -59,17 +59,24 @@ LDDocument* DocumentManager::getDocumentByName (QString filename) { - LDDocument* doc = findDocumentByName (filename); - - if (doc == nullptr) + if (not filename.isEmpty()) { - bool tmp = m_loadingMainFile; - m_loadingMainFile = false; - doc = openDocument (filename, true, true); - m_loadingMainFile = tmp; + LDDocument* doc = findDocumentByName (filename); + + if (doc == nullptr) + { + bool tmp = m_loadingMainFile; + m_loadingMainFile = false; + doc = openDocument (filename, true, true); + m_loadingMainFile = tmp; + } + + return doc; } - - return doc; + else + { + return nullptr; + } } void DocumentManager::openMainModel (QString path) @@ -153,10 +160,13 @@ LDDocument* DocumentManager::findDocumentByName (QString name) { - for (LDDocument* document : m_documents) + if (not name.isEmpty()) { - if (isOneOf (name, document->name(), document->defaultName())) - return document; + for (LDDocument* document : m_documents) + { + if (isOneOf (name, document->name(), document->defaultName())) + return document; + } } return nullptr;
--- a/src/editmodes/selectMode.cpp Sun Mar 18 12:00:39 2018 +0200 +++ b/src/editmodes/selectMode.cpp Sun Mar 18 12:33:29 2018 +0200 @@ -21,7 +21,7 @@ #include "../canvas.h" #include "../mainwindow.h" #include "../lddocument.h" -#include "../widgets/vertexobjecteditor.h" +#include "../guiutilities.h" SelectMode::SelectMode (Canvas* canvas) : Super (canvas), @@ -134,10 +134,8 @@ if (index.isValid()) { - // TODO: LDObject* object = currentDocument()->lookup(index); - VertexObjectEditor editor {object}; - editor.exec(); + ::editObject(this->m_window, object); m_window->endAction(); return true; }
--- a/src/guiutilities.cpp Sun Mar 18 12:00:39 2018 +0200 +++ b/src/guiutilities.cpp Sun Mar 18 12:33:29 2018 +0200 @@ -24,6 +24,9 @@ #include "lddocument.h" #include "dialogs/colorselector.h" #include "mainwindow.h" +#include "linetypes/modelobject.h" +#include "dialogs/subfilereferenceeditor.h" +#include "widgets/vertexobjecteditor.h" GuiUtilities::GuiUtilities (QObject* parent) : QObject (parent), @@ -167,16 +170,18 @@ } } -void setupColorButton(QWidget* parent, QPushButton* button, LDColor* color) +void editObject(MainWindow* parent, LDObject* object) { - QObject::connect( - button, - &QPushButton::clicked, - [&]() - { - if (ColorSelector::selectColor(parent, *color, *color)) - ::setColorButton(button, *color); - } - ); - setColorButton(button, *color); + if (object->type() == LDObjectType::SubfileReference) + { + LDSubfileReference* reference = static_cast<LDSubfileReference*>(object); + SubfileReferenceEditor editor {reference, parent}; + editor.setPrimitivesTree(parent->primitives()); + editor.exec(); + } + else + { + VertexObjectEditor editor {object, parent}; + editor.exec(); + } }
--- a/src/guiutilities.h Sun Mar 18 12:00:39 2018 +0200 +++ b/src/guiutilities.h Sun Mar 18 12:33:29 2018 +0200 @@ -39,4 +39,4 @@ QIcon makeColorIcon(LDColor color, int size); void setColorButton(class QPushButton* button, LDColor color); -void setupColorButton(QWidget* parent, QPushButton* button, LDColor* color); +void editObject(MainWindow* parent, LDObject* object);
--- a/src/lddocument.cpp Sun Mar 18 12:00:39 2018 +0200 +++ b/src/lddocument.cpp Sun Mar 18 12:33:29 2018 +0200 @@ -511,21 +511,35 @@ */ void LDDocument::inlineContents(Model& model, bool deep, bool renderinline) { - if (m_manager->preInline(this, model, deep, renderinline)) - return; // Manager dealt with this inline - - for (LDObject* object : objects()) + // Protect against circular references by not inling if called by recursion again. + if (not m_isInlining) { - // Skip those without effect on the model meaning - if (not object->isScemantic()) - continue; + m_isInlining = true; - // Got another sub-file reference, recurse and inline it too if we're deep-inlining. - // If not, just add it into the objects normally. - if (deep and object->type() == LDObjectType::SubfileReference) - static_cast<LDSubfileReference*>(object)->inlineContents(documentManager(), model, deep, renderinline); - else - model.insertCopy(model.size(), object); + // First ask the manager to deal with this inline (this takes logoed studs into account) + if (not m_manager->preInline(this, model, deep, renderinline)) + { + for (LDObject* object : objects()) + { + // Skip those without effect on the model meaning + if (object->isScemantic()) + { + // Got another sub-file reference, recurse and inline it too if we're deep-inlining. + // If not, just add it into the objects normally. + if (deep and object->type() == LDObjectType::SubfileReference) + { + LDSubfileReference* reference = static_cast<LDSubfileReference*>(object); + reference->inlineContents(documentManager(), model, deep, renderinline); + } + else + { + model.insertCopy(model.size(), object); + } + } + } + } + + m_isInlining = false; } }
--- a/src/lddocument.h Sun Mar 18 12:00:39 2018 +0200 +++ b/src/lddocument.h Sun Mar 18 12:33:29 2018 +0200 @@ -147,6 +147,7 @@ bool m_verticesOutdated = true; bool m_isBeingDestroyed = false; bool m_needsRecache = true; // The next polygon inline of this document rebuilds stored polygon data. + bool m_isInlining = false; long m_savePosition; int m_tabIndex; int m_triangleCount;
--- a/src/linetypes/modelobject.h Sun Mar 18 12:00:39 2018 +0200 +++ b/src/linetypes/modelobject.h Sun Mar 18 12:33:29 2018 +0200 @@ -123,7 +123,7 @@ private: Vertex m_position; - Matrix m_transformationMatrix; + Matrix m_transformationMatrix = Matrix::identity; }; /*
--- a/src/toolsets/basictoolset.cpp Sun Mar 18 12:00:39 2018 +0200 +++ b/src/toolsets/basictoolset.cpp Sun Mar 18 12:33:29 2018 +0200 @@ -37,6 +37,7 @@ #include "../parser.h" #include "../widgets/vertexobjecteditor.h" #include "basictoolset.h" +#include "guiutilities.h" BasicToolset::BasicToolset (MainWindow *parent) : Toolset (parent) {} @@ -293,44 +294,35 @@ } template<typename T> -static T* createObject(MainWindow* window) +static void createObject(MainWindow* window) { - return window->currentDocument()->emplaceAt<T>(window->suggestInsertPoint()); -} - -template<typename T> -static void createVertexObject(MainWindow* window) -{ - LDObject* object = createObject<T>(window); - VertexObjectEditor editor {object}; - editor.exec(); + LDObject* object = window->currentDocument()->emplaceAt<T>(window->suggestInsertPoint()); + ::editObject(window, object); } void BasicToolset::newSubfile() { - LDSubfileReference* reference = createObject<LDSubfileReference>(this->m_window); - SubfileReferenceEditor editor {reference, this->m_window}; - editor.exec(); + createObject<LDSubfileReference>(this->m_window); } void BasicToolset::newLine() { - createVertexObject<LDEdgeLine>(this->m_window); + createObject<LDEdgeLine>(this->m_window); } void BasicToolset::newTriangle() { - createVertexObject<LDTriangle>(this->m_window); + createObject<LDTriangle>(this->m_window); } void BasicToolset::newQuadrilateral() { - createVertexObject<LDQuadrilateral>(this->m_window); + createObject<LDQuadrilateral>(this->m_window); } void BasicToolset::newConditionalLine() { - createVertexObject<LDConditionalEdge>(this->m_window); + createObject<LDConditionalEdge>(this->m_window); } void BasicToolset::newComment()
--- a/src/widgets/vertexobjecteditor.cpp Sun Mar 18 12:00:39 2018 +0200 +++ b/src/widgets/vertexobjecteditor.cpp Sun Mar 18 12:33:29 2018 +0200 @@ -14,7 +14,17 @@ this->ui.setupUi(this); this->ui.verticesContainer->setLayout(this->vertexGrid); this->currentColor = this->object->color(); - ::setupColorButton(parent, this->ui.color, &this->currentColor); + setColorButton(this->ui.color, this->currentColor); + + connect( + this->ui.color, + &QPushButton::clicked, + [&]() + { + if (ColorSelector::selectColor(this, this->currentColor, this->currentColor)) + ::setColorButton(this->ui.color, this->currentColor); + } + ); for (int i : range(0, 1, object->numVertices() - 1)) {