# HG changeset patch # User Teemu Piippo # Date 1656509629 -10800 # Node ID d862721d19a3ca626158489de0b856f0cb194454 # Parent daa8770b9d26d02e5de069c8c2611cde7c42350c Fixed ModelId being used to identify both models and elements, added ElementId to identify elements diff -r daa8770b9d26 -r d862721d19a3 src/basics.h --- a/src/basics.h Wed Jun 29 16:21:44 2022 +0300 +++ b/src/basics.h Wed Jun 29 16:33:49 2022 +0300 @@ -19,6 +19,7 @@ #pragma once #include #include +#include #include #include #include @@ -52,6 +53,12 @@ Q_DECLARE_METATYPE(glm::vec3) Q_DECLARE_METATYPE(glm::mat4) +struct ModelId +{ + std::int32_t value; + constexpr auto operator<=>(const ModelId&) const = default; +}; + //! \brief count the amount of elements in a basic array template constexpr int countof(T(&)[N]) diff -r daa8770b9d26 -r d862721d19a3 src/gl/compiler.cpp --- a/src/gl/compiler.cpp Wed Jun 29 16:21:44 2022 +0300 +++ b/src/gl/compiler.cpp Wed Jun 29 16:33:49 2022 +0300 @@ -309,7 +309,7 @@ } } -ModelId gl::idFromUcharColor(const std::array& data) +ElementId gl::idFromUcharColor(const std::array& data) { return { static_cast(data[0]) | @@ -332,7 +332,7 @@ shaderObject.vertexArray.release(); } -void gl::setModelShaderSelectedObjects(gl::ModelShaders* shaders, const QSet &ids) +void gl::setModelShaderSelectedObjects(gl::ModelShaders* shaders, const QSet &ids) { for (ModelShaders::ShaderObject& object : shaders->shaderObjects) { diff -r daa8770b9d26 -r d862721d19a3 src/gl/compiler.h --- a/src/gl/compiler.h Wed Jun 29 16:21:44 2022 +0300 +++ b/src/gl/compiler.h Wed Jun 29 16:33:49 2022 +0300 @@ -80,9 +80,9 @@ void initializeModelShaders(ModelShaders* modelShaders); void bindModelShaderVertexArray(gl::ModelShaders* shaders, gl::ArrayClass arrayClass); void releaseModelShaderVertexArray(gl::ModelShaders* shaders, gl::ArrayClass arrayClass); - void setModelShaderSelectedObjects(gl::ModelShaders* shaders, const QSet& ids); + void setModelShaderSelectedObjects(gl::ModelShaders* shaders, const QSet& ids); std::size_t vertexCount(const ModelShaders *shaders, gl::ArrayClass arrayClass); - ModelId idFromUcharColor(const std::array& data); + ElementId idFromUcharColor(const std::array& data); template void setShaderUniform(gl::ModelShaders* shaders, const char* uniformName, Ts&&... args) diff -r daa8770b9d26 -r d862721d19a3 src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Wed Jun 29 16:21:44 2022 +0300 +++ b/src/gl/partrenderer.cpp Wed Jun 29 16:33:49 2022 +0300 @@ -432,7 +432,7 @@ viewportVector); } -ModelId PartRenderer::pick(QPoint where) +ElementId PartRenderer::pick(QPoint where) { // y is flipped, take that into account where.setY(this->height() - where.y()); @@ -489,7 +489,7 @@ return this->highlighted; } -void PartRenderer::setSelection(const QSet& selection) +void PartRenderer::setSelection(const QSet& selection) { Q_ASSERT(not selection.contains({0})); gl::setModelShaderSelectedObjects(&this->shaders, selection); diff -r daa8770b9d26 -r d862721d19a3 src/gl/partrenderer.h --- a/src/gl/partrenderer.h Wed Jun 29 16:21:44 2022 +0300 +++ b/src/gl/partrenderer.h Wed Jun 29 16:33:49 2022 +0300 @@ -43,8 +43,8 @@ std::optional screenToModelCoordinates(const QPointF& point, const Plane& plane) const; QPointF modelToScreenCoordinates(const glm::vec3& point) const; bool isDark() const; - ModelId pick(QPoint where); - void setSelection(const QSet& selectedIds); + ElementId pick(QPoint where); + void setSelection(const QSet& selectedIds); Q_SIGNALS: void projectionMatrixChanged(const glm::mat4& newMatrix); void modelMatrixChanged(const glm::mat4& newMatrix); diff -r daa8770b9d26 -r d862721d19a3 src/layers/edittools.cpp --- a/src/layers/edittools.cpp Wed Jun 29 16:21:44 2022 +0300 +++ b/src/layers/edittools.cpp Wed Jun 29 16:33:49 2022 +0300 @@ -299,7 +299,7 @@ switch(this->mode) { case SelectMode: if (event->button() == Qt::LeftButton) { - const ModelId highlighted = this->renderer->pick(event->pos()); + const ElementId highlighted = this->renderer->pick(event->pos()); Q_EMIT this->select({highlighted}, false); } break; diff -r daa8770b9d26 -r d862721d19a3 src/layers/edittools.h --- a/src/layers/edittools.h Wed Jun 29 16:21:44 2022 +0300 +++ b/src/layers/edittools.h Wed Jun 29 16:33:49 2022 +0300 @@ -61,7 +61,7 @@ Q_SIGNALS: void newStatusText(const QString& newStatusText); void modelAction(const ModelAction& action); - void select(const QSet& ids, bool retain); + void select(const QSet& ids, bool retain); protected: void mvpMatrixChanged(const glm::mat4& matrix) override; void mouseMoved(const QMouseEvent* event) override; diff -r daa8770b9d26 -r d862721d19a3 src/main.cpp --- a/src/main.cpp Wed Jun 29 16:21:44 2022 +0300 +++ b/src/main.cpp Wed Jun 29 16:33:49 2022 +0300 @@ -398,10 +398,10 @@ return subWindow; } -static QSet resolveIdsFromSelection(const ModelData* data) +static QSet resolveIdsFromSelection(const ModelData* data) { const auto selection = data->itemSelectionModel->selection(); - QSet selectedIndexes; + QSet selectedIndexes; for (const QModelIndex& qindex : selection.indexes()) { const std::size_t row = unsigned_cast(qindex.row()); selectedIndexes.insert(data->model->idAt(row)); @@ -548,13 +548,13 @@ QObject::connect( data->tools.get(), &EditTools::select, - [modelId, &documents](const QSet& indices, bool retain) { + [modelId, &documents](const QSet& indices, bool retain) { ModelData* data = findModelData(&documents, modelId); if (data != nullptr) { if (not retain) { data->itemSelectionModel->clear(); } - for (const ModelId id : indices) { + for (const ElementId id : indices) { opt index = data->model->find(id); if (index.has_value()) { const QModelIndex qindex = data->model->index(*index); diff -r daa8770b9d26 -r d862721d19a3 src/model.cpp --- a/src/model.cpp Wed Jun 29 16:21:44 2022 +0300 +++ b/src/model.cpp Wed Jun 29 16:33:49 2022 +0300 @@ -173,10 +173,10 @@ { } -ModelId Model::append(const ModelElement &value) +ElementId Model::append(const ModelElement &value) { const std::size_t position = this->size(); - const ModelId id = this->runningId; + const ElementId id = this->runningId; this->runningId.value += 1; const int row = narrow(signed_cast(this->size())); Q_EMIT this->beginInsertRows({}, row, row); @@ -191,7 +191,7 @@ return this->body[position].data; } -ModelId Model::idAt(std::size_t position) const +ElementId Model::idAt(std::size_t position) const { return this->body[position].id; } @@ -203,7 +203,7 @@ Q_EMIT this->dataChanged(index, index); } -std::optional Model::find(ModelId id) const +std::optional Model::find(ElementId id) const { return pointerToOptional(findInMap(this->positions, id)); } diff -r daa8770b9d26 -r d862721d19a3 src/model.h --- a/src/model.h Wed Jun 29 16:21:44 2022 +0300 +++ b/src/model.h Wed Jun 29 16:33:49 2022 +0300 @@ -194,13 +194,13 @@ } QString modelElementToString(const ModelElement& element); -struct ModelId +struct ElementId { std::int32_t value; - constexpr auto operator<=>(const ModelId& other) const = default; + constexpr auto operator<=>(const ElementId& other) const = default; }; -constexpr auto qHash(ModelId id) +constexpr auto qHash(ElementId id) { return qHash(id.value); } @@ -210,19 +210,19 @@ Q_OBJECT struct Entry { ModelElement data; - ModelId id; + ElementId id; }; std::vector body; - std::map positions; - ModelId runningId = {1}; + std::map positions; + ElementId runningId = {1}; public: explicit Model(QObject* parent); virtual ~Model(); - ModelId append(const ModelElement& value); + ElementId append(const ModelElement& value); const ModelElement& at(std::size_t position) const; - ModelId idAt(std::size_t position) const; + ElementId idAt(std::size_t position) const; void assignAt(std::size_t position, const ModelElement& element); - std::optional find(ModelId id) const; + std::optional find(ElementId id) const; void remove(std::size_t index); int rowCount(const QModelIndex&) const override; QVariant data(const QModelIndex& index, int role) const override; diff -r daa8770b9d26 -r d862721d19a3 src/polygoncache.cpp --- a/src/polygoncache.cpp Wed Jun 29 16:21:44 2022 +0300 +++ b/src/polygoncache.cpp Wed Jun 29 16:33:49 2022 +0300 @@ -104,7 +104,7 @@ for (std::size_t i = 0; i < model->size(); i += 1) { const ModelElement& element = (*model)[i]; - const ModelId id = model->idAt(i); + const ElementId id = model->idAt(i); collectPolygons(element, winding, context, [&result, winding, id](const PolygonElement& poly){ result.push_back({poly, id}); diff -r daa8770b9d26 -r d862721d19a3 src/polygoncache.h --- a/src/polygoncache.h Wed Jun 29 16:21:44 2022 +0300 +++ b/src/polygoncache.h Wed Jun 29 16:33:49 2022 +0300 @@ -2,11 +2,12 @@ #include "src/basics.h" #include "src/model.h" #include "src/gl/common.h" +#include "src/documentmanager.h" template struct WithId : T { - ModelId id; + ElementId id; }; struct GetPolygonsContext diff -r daa8770b9d26 -r d862721d19a3 src/vertexmap.cpp --- a/src/vertexmap.cpp Wed Jun 29 16:21:44 2022 +0300 +++ b/src/vertexmap.cpp Wed Jun 29 16:33:49 2022 +0300 @@ -158,7 +158,7 @@ info.transformSet = true; } float scale = 1.0f; - for (const ModelId objectId : info.objects) + for (const ElementId objectId : info.objects) { const std::optional index = model->find(objectId); if (index.has_value()) { diff -r daa8770b9d26 -r d862721d19a3 src/vertexmap.h --- a/src/vertexmap.h Wed Jun 29 16:21:44 2022 +0300 +++ b/src/vertexmap.h Wed Jun 29 16:33:49 2022 +0300 @@ -14,7 +14,7 @@ struct VertexInfo { glm::vec3 point; - std::set objects; + std::set objects; bool transformSet = false; glm::mat4 transform; };