From d48b236fb0265d28b889141b03e2fdd100d45e6a Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 7 Mar 2016 09:35:10 +0300 Subject: [PATCH] [editor] Generate new feature ID for created features. --- indexer/osm_editor.cpp | 22 ++++++++++++++-------- indexer/osm_editor.hpp | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index 2b966fd828..562e619693 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -683,16 +683,22 @@ NewFeatureCategories Editor::GetNewFeatureCategories() const return res; } -namespace +FeatureID Editor::GenerateNewFeatureId(MwmSet::MwmId const & id) { -FeatureID GenerateNewFeatureId(FeatureID const & oldFeatureId) -{ - // TODO(AlexZ): Stable & unique features ID generation. - // TODO(vng): Looks like new feature indexes should uninterruptedly continue after existing indexes in mwm file. - static uint32_t newIndex = 0x0effffff; - return FeatureID(oldFeatureId.m_mwmId, newIndex++); + // TODO(vng): Double-check if new feature indexes should uninterruptedly continue after existing indexes in mwm file. + uint32_t featureIndex = kStartIndexForCreatedFeatures; + auto const found = m_features.find(id); + if (found != m_features.end()) + { + // Scan all already created features and choose next available ID. + for (auto const & feature : found->second) + { + if (feature.second.m_status == FeatureStatus::Created && featureIndex <= feature.first) + featureIndex = feature.first + 1; + } + } + return FeatureID(id, featureIndex); } -} // namespace bool Editor::CreatePoint(uint32_t type, m2::PointD const & mercator, MwmSet::MwmId const & id, EditableMapObject & outFeature) { diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp index 003cf85cc0..87520b0013 100644 --- a/indexer/osm_editor.hpp +++ b/indexer/osm_editor.hpp @@ -132,6 +132,7 @@ private: /// Notify framework that something has changed and should be redisplayed. void Invalidate(); + FeatureID GenerateNewFeatureId(MwmSet::MwmId const & id); EditableProperties GetEditablePropertiesForTypes(feature::TypesHolder const & types) const; struct FeatureTypeInfo