--- a/src/documentmanager.cpp Tue Nov 02 15:43:57 2021 +0200 +++ b/src/documentmanager.cpp Thu Mar 03 11:42:52 2022 +0200 @@ -45,8 +45,10 @@ const QString name = makeNewModelName(); this->openModels[modelId] = ModelInfo{ .model = std::make_unique<Model>(), + .id = modelId, .opentype = OpenType::ManuallyOpened, }; + this->makePolygonCacheForModel(modelId); return modelId; } @@ -141,7 +143,8 @@ if (file.error() == QFile::NoError) { const ModelId modelId{++this->modelIdCounter}; - this->openModels[modelId] = {std::move(newModel), path, openType}; + this->openModels[modelId] = {std::move(newModel), modelId, path, openType}; + this->makePolygonCacheForModel(modelId); result = modelId; } else @@ -299,6 +302,19 @@ return result; } +PolygonCache *DocumentManager::getPolygonCacheForModel(ModelId modelId) +{ + auto it = this->polygonCaches.find(modelId); + if (it != this->polygonCaches.end()) + { + return &it->second; + } + else + { + return nullptr; + } +} + /** * @brief Cleans up and erases models that are no longer required. */ @@ -311,6 +327,12 @@ and it->second.opentype == OpenType::AutomaticallyOpened and not this->isReferencedByAnything(it->first) ) { + // Remove its polygon cache + const auto polygonCache = this->polygonCaches.find(it->first); + if (polygonCache != this->polygonCaches.end()) + { + this->polygonCaches.erase(polygonCache); + } // Remove the model this->openModels.erase(it); // We need to start over now. It is possible that other models that previously @@ -345,6 +367,18 @@ return false; } +void DocumentManager::makePolygonCacheForModel(const ModelId modelId) +{ + Model* model = this->getModelById(modelId); + if (model != nullptr) + { + this->polygonCaches.emplace( + std::piecewise_construct, + std::forward_as_tuple(modelId), + std::forward_as_tuple(model)); + } +} + static QString findFile(QString referenceName, const QString& path, const LibraryManager& libraries) { // Try to find the file in the same place as the model itself