Wed, 29 Jun 2022 16:33:49 +0300
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
src/basics.h | file | annotate | diff | comparison | revisions | |
src/gl/compiler.cpp | file | annotate | diff | comparison | revisions | |
src/gl/compiler.h | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.cpp | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.h | file | annotate | diff | comparison | revisions | |
src/layers/edittools.cpp | file | annotate | diff | comparison | revisions | |
src/layers/edittools.h | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/model.cpp | file | annotate | diff | comparison | revisions | |
src/model.h | file | annotate | diff | comparison | revisions | |
src/polygoncache.cpp | file | annotate | diff | comparison | revisions | |
src/polygoncache.h | file | annotate | diff | comparison | revisions | |
src/vertexmap.cpp | file | annotate | diff | comparison | revisions | |
src/vertexmap.h | file | annotate | diff | comparison | revisions |
--- 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 <algorithm> #include <cmath> +#include <cinttypes> #include <compare> #include <deque> #include <memory> @@ -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<typename T, int N> constexpr int countof(T(&)[N])
--- 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<GLubyte, 3>& data) +ElementId gl::idFromUcharColor(const std::array<GLubyte, 3>& data) { return { static_cast<std::int32_t>(data[0]) | @@ -332,7 +332,7 @@ shaderObject.vertexArray.release(); } -void gl::setModelShaderSelectedObjects(gl::ModelShaders* shaders, const QSet<ModelId> &ids) +void gl::setModelShaderSelectedObjects(gl::ModelShaders* shaders, const QSet<ElementId> &ids) { for (ModelShaders::ShaderObject& object : shaders->shaderObjects) {
--- 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<ModelId>& ids); + void setModelShaderSelectedObjects(gl::ModelShaders* shaders, const QSet<ElementId>& ids); std::size_t vertexCount(const ModelShaders *shaders, gl::ArrayClass arrayClass); - ModelId idFromUcharColor(const std::array<GLubyte, 3>& data); + ElementId idFromUcharColor(const std::array<GLubyte, 3>& data); template<typename... Ts> void setShaderUniform(gl::ModelShaders* shaders, const char* uniformName, Ts&&... args)
--- 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<ModelId>& selection) +void PartRenderer::setSelection(const QSet<ElementId>& selection) { Q_ASSERT(not selection.contains({0})); gl::setModelShaderSelectedObjects(&this->shaders, selection);
--- 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<glm::vec3> 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<ModelId>& selectedIds); + ElementId pick(QPoint where); + void setSelection(const QSet<ElementId>& selectedIds); Q_SIGNALS: void projectionMatrixChanged(const glm::mat4& newMatrix); void modelMatrixChanged(const glm::mat4& newMatrix);
--- 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;
--- 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<ModelId>& ids, bool retain); + void select(const QSet<ElementId>& ids, bool retain); protected: void mvpMatrixChanged(const glm::mat4& matrix) override; void mouseMoved(const QMouseEvent* event) override;
--- 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<ModelId> resolveIdsFromSelection(const ModelData* data) +static QSet<ElementId> resolveIdsFromSelection(const ModelData* data) { const auto selection = data->itemSelectionModel->selection(); - QSet<ModelId> selectedIndexes; + QSet<ElementId> 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<ModelId>& indices, bool retain) { + [modelId, &documents](const QSet<ElementId>& 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<int> index = data->model->find(id); if (index.has_value()) { const QModelIndex qindex = data->model->index(*index);
--- 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<int>(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<std::size_t> Model::find(ModelId id) const +std::optional<std::size_t> Model::find(ElementId id) const { return pointerToOptional(findInMap(this->positions, id)); }
--- 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<Entry> body; - std::map<ModelId, std::size_t> positions; - ModelId runningId = {1}; + std::map<ElementId, std::size_t> 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<std::size_t> find(ModelId id) const; + std::optional<std::size_t> 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;
--- 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});
--- 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<typename T> struct WithId : T { - ModelId id; + ElementId id; }; struct GetPolygonsContext
--- 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<int> index = model->find(objectId); if (index.has_value()) {