Mon, 19 Mar 2018 12:44:27 +0200
red/green view rework complete
--- a/src/documentmanager.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/documentmanager.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -319,7 +319,9 @@ int numWarnings; Parser parser {*fp}; - load->header = parser.parseHeader(); + Winding winding = NoWinding; + load->header = parser.parseHeader(winding); + load->setWinding(winding); parser.parseBody(*load); fp->close(); fp->deleteLater();
--- a/src/glcompiler.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/glcompiler.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -24,6 +24,7 @@ #include "guiutilities.h" #include "documentmanager.h" #include "grid.h" +#include "algorithms/invert.h" void checkGLError(HierarchyElement* element, QString file, int line) { @@ -375,8 +376,10 @@ case LDObjectType::SubfileReference: { LDSubfileReference* subfileReference = static_cast<LDSubfileReference*>(object); - // TODO: move winding to Model and use it here - auto data = subfileReference->inlinePolygons(m_documents, CounterClockwise); + auto data = subfileReference->inlinePolygons( + m_documents, + m_renderer->model()->winding() + ); for (LDPolygon& poly : data) compilePolygon (poly, index, info); @@ -407,6 +410,9 @@ const QModelIndex& polygonOwnerIndex, ObjectVboData& objectInfo ) { + if (m_renderer->model()->winding() == Clockwise) + ::invertPolygon(poly); + VboClass surface; int vertexCount; @@ -486,6 +492,12 @@ return m_vboSizes[vbonum]; } +void GLCompiler::fullUpdate() +{ + m_objectInfo.clear(); + recompile(); +} + /* * Recompiles the entire model. */
--- a/src/glcompiler.h Mon Mar 19 12:24:59 2018 +0200 +++ b/src/glcompiler.h Mon Mar 19 12:44:27 2018 +0200 @@ -40,6 +40,7 @@ int vboSize (int vbonum) const; QItemSelectionModel* selectionModel() const; void setSelectionModel(QItemSelectionModel* _selectionModel); + void fullUpdate(); static int vboNumber (VboClass surface, VboSubclass complement);
--- a/src/glrenderer.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/glrenderer.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -1040,3 +1040,9 @@ { this->m_compiler->setSelectionModel(selectionModel); } + +void GLRenderer::fullUpdate() +{ + this->m_compiler->fullUpdate(); + update(); +}
--- a/src/glrenderer.h Mon Mar 19 12:24:59 2018 +0200 +++ b/src/glrenderer.h Mon Mar 19 12:44:27 2018 +0200 @@ -61,6 +61,7 @@ Camera camera() const; GLCamera& currentCamera(); const GLCamera& currentCamera() const; + Q_SLOT void fullUpdate(); Qt::KeyboardModifiers keyboardModifiers() const; const Model* model() const; QPoint const& mousePosition() const;
--- a/src/lddocument.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/lddocument.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -221,7 +221,7 @@ return true; } -static QString headerToString(const LDHeader& header) +static QString headerToString(const Model& model, const LDHeader& header) { QString result; @@ -276,7 +276,7 @@ result += "\r\n"; - switch (header.winding) + switch (model.winding()) { case CounterClockwise: result += "0 BFC CERTIFY CCW\r\n"; @@ -350,7 +350,7 @@ if (this->header.type != LDHeader::NoHeader) { header.name = LDDocument::shortenName(path); - data += headerToString(this->header).toUtf8(); + data += headerToString(*this, this->header).toUtf8(); } // File is open, now save the model to it. Note that LDraw requires files to have DOS line endings. @@ -531,7 +531,7 @@ LDSubfileReference* reference = static_cast<LDSubfileReference*>(object); reference->inlineContents( documentManager(), - this->header.winding, + this->winding(), model, deep, renderinline
--- a/src/lddocument.h Mon Mar 19 12:24:59 2018 +0200 +++ b/src/lddocument.h Mon Mar 19 12:44:27 2018 +0200 @@ -62,7 +62,6 @@ QString help; QString keywords; QVector<HistoryEntry> history; - Winding winding = NoWinding; enum { UnspecifiedLicense,
--- a/src/linetypes/modelobject.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/linetypes/modelobject.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -160,7 +160,7 @@ bool result = false; result ^= (reference->isInverted()); result ^= (reference->transformationMatrix().determinant() < 0); - result ^= (reference->fileInfo(context)->header.winding != winding); + result ^= (reference->fileInfo(context)->winding() != winding); return result; }
--- a/src/mainwindow.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/mainwindow.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -915,8 +915,9 @@ { document->setFrozen(false); print ("Opened %1", document->name()); - getRendererForDocument(document); + Canvas* canvas = getRendererForDocument(document); updateDocumentList(); + connect(document, &LDDocument::windingChanged, canvas, &Canvas::fullUpdate); } } @@ -948,7 +949,7 @@ updateTitle(); print ("Changed document to %1", document->getDisplayName()); ui.objectList->setModel(document); - ui.header->setHeader(&document->header); + ui.header->setDocument(document); QItemSelectionModel* selection = m_selections.value(document); if (selection == nullptr)
--- a/src/model.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/model.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -414,6 +414,17 @@ } } +Winding Model::winding() const +{ + return this->_winding; +} + +void Model::setWinding(Winding winding) +{ + this->_winding = winding; + emit windingChanged(this->_winding); +} + int countof(Model& model) { return model.size();
--- a/src/model.h Mon Mar 19 12:24:59 2018 +0200 +++ b/src/model.h Mon Mar 19 12:44:27 2018 +0200 @@ -107,6 +107,8 @@ LDObject* lookup(const QModelIndex& index) const; QColor pickingColorForObject(const QModelIndex& objectIndex) const; QModelIndex objectByPickingColor(const QColor& color) const; + Winding winding() const; + void setWinding(Winding winding); bool moveRows( const QModelIndex& sourceParent, @@ -123,6 +125,7 @@ void objectAdded(const QModelIndex& object); void aboutToRemoveObject(const QModelIndex& index); void objectModified(LDObject* object); + void windingChanged(Winding newWinding); protected: template<typename T, typename... Args> T* constructObject(Args&& ...args); @@ -133,6 +136,7 @@ class DocumentManager* _manager; mutable int _triangleCount = 0; mutable bool _needsTriangleRecount; + Winding _winding = NoWinding; private: void installObject(int row, LDObject* object);
--- a/src/parser.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/parser.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -57,8 +57,11 @@ * · ParseFailure: the header line was parsed incorrectly and needs to be handled otherwise. * · StopParsing: the line does not belong in the header and header parsing needs to stop. */ -Parser::HeaderParseResult Parser::parseHeaderLine(LDHeader& header, const QString& line) -{ +Parser::HeaderParseResult Parser::parseHeaderLine( + LDHeader& header, + Winding& winding, + const QString& line +) { if (line.isEmpty()) { return ParseSuccess; @@ -98,17 +101,17 @@ } else if (line == "0 BFC CERTIFY CCW") { - header.winding = CounterClockwise; + winding = CounterClockwise; return ParseSuccess; } else if (line == "0 BFC CERTIFY CW") { - header.winding = Clockwise; + winding = Clockwise; return ParseSuccess; } else if (line == "0 BFC NOCERTIFY") { - header.winding = NoWinding; + winding = NoWinding; return ParseSuccess; } else if (line.startsWith("0 !HISTORY ")) @@ -193,7 +196,7 @@ * Parses the header from the device given at construction and returns * the resulting header structure. */ -LDHeader Parser::parseHeader() +LDHeader Parser::parseHeader(Winding& winding) { LDHeader header = {}; @@ -209,7 +212,7 @@ while (not this->device.atEnd()) { const QString& line = this->readLine(); - auto result = parseHeaderLine(header, line); + auto result = parseHeaderLine(header, winding, line); if (result == ParseFailure) {
--- a/src/parser.h Mon Mar 19 12:24:59 2018 +0200 +++ b/src/parser.h Mon Mar 19 12:44:27 2018 +0200 @@ -32,7 +32,7 @@ Parser(QIODevice& device, QObject* parent = nullptr); - LDHeader parseHeader(); + LDHeader parseHeader(Winding& winding); void parseBody(Model& model); static LDObject* parseFromString(Model& model, int position, QString line); @@ -48,7 +48,7 @@ enum HeaderParseResult {ParseSuccess, ParseFailure, StopParsing}; QString readLine(); - HeaderParseResult parseHeaderLine(LDHeader& header, const QString& line); + HeaderParseResult parseHeaderLine(LDHeader& header, Winding& winding, const QString& line); QIODevice& device; QStringList bag;
--- a/src/toolsets/basictoolset.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/toolsets/basictoolset.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -116,7 +116,7 @@ Model inlined {m_documents}; reference->inlineContents( m_documents, - currentDocument()->header.winding, + currentDocument()->winding(), inlined, deep, false
--- a/src/widgets/headeredit.cpp Mon Mar 19 12:24:59 2018 +0200 +++ b/src/widgets/headeredit.cpp Mon Mar 19 12:44:27 2018 +0200 @@ -74,10 +74,7 @@ [&](int index) { if (this->hasValidHeader()) - { - this->m_header->winding = static_cast<Winding>(index); - emit windingChanged(this->m_header->winding); - } + this->m_model->setWinding(static_cast<Winding>(index)); } ); connect( @@ -185,8 +182,10 @@ delete &this->ui; } -void HeaderEdit::setHeader(LDHeader* header) +void HeaderEdit::setDocument(LDDocument* document) { + LDHeader* header = &document->header; + this->m_model = document; this->m_header = header; this->ui.description->setText(header->description); this->ui.author->setText(header->author); @@ -196,18 +195,13 @@ this->ui.physicalColor->setChecked(header->qualfiers & LDHeader::Physical_Color); this->ui.flexibleSection->setChecked(header->qualfiers & LDHeader::Flexible_Section); this->ui.cmdline->setText(header->cmdline); - this->ui.winding->setCurrentIndex(header->winding); + this->ui.winding->setCurrentIndex(document->winding()); this->ui.keywords->document()->setPlainText(header->keywords); this->ui.help->document()->setPlainText(header->help); this->headerHistoryModel->setHeader(header); this->setEnabled(this->hasValidHeader()); } -LDHeader* HeaderEdit::header() const -{ - return this->m_header; -} - bool HeaderEdit::hasValidHeader() const { return this->m_header != nullptr and this->m_header->type != LDHeader::NoHeader;
--- a/src/widgets/headeredit.h Mon Mar 19 12:24:59 2018 +0200 +++ b/src/widgets/headeredit.h Mon Mar 19 12:44:27 2018 +0200 @@ -28,18 +28,17 @@ HeaderEdit(QWidget* parent = nullptr); ~HeaderEdit(); - void setHeader(LDHeader* header); - LDHeader* header() const; + void setDocument(LDDocument* document); bool hasValidHeader() const; signals: void descriptionChanged(const QString& newDescription); - void windingChanged(Winding newWinding); private: class Ui_HeaderEdit& ui; class HeaderHistoryModel* headerHistoryModel = nullptr; LDHeader* m_header = nullptr; + Model* m_model = nullptr; void moveRows(int direction); };