diff options
author | Sergey Yershov <syershov@maps.me> | 2018-06-18 11:39:14 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-06-22 12:22:30 +0300 |
commit | 37d3d2f748769f024a0e6b8a969822746de93971 (patch) | |
tree | 2e4dec2e01a056f5d03a9e91a3f3e8ac15cc777e /editor | |
parent | c92fe0a11d20e99ae47c723a2746d44d304a5cd0 (diff) |
[indexer][editor] Refactor Index into DataSource
Remove namespace datasource
Diffstat (limited to 'editor')
-rw-r--r-- | editor/CMakeLists.txt | 1 | ||||
-rw-r--r-- | editor/editable_data_source.hpp | 7 | ||||
-rw-r--r-- | editor/editable_feature_source.cpp | 11 | ||||
-rw-r--r-- | editor/editable_feature_source.hpp | 22 | ||||
-rw-r--r-- | editor/editor_tests/osm_editor_test.cpp | 49 | ||||
-rw-r--r-- | editor/editor_tests/osm_editor_test.hpp | 12 | ||||
-rw-r--r-- | editor/edits_migration.cpp | 15 | ||||
-rw-r--r-- | editor/edits_migration.hpp | 3 | ||||
-rw-r--r-- | editor/osm_editor.cpp | 101 | ||||
-rw-r--r-- | editor/osm_editor.hpp | 16 |
10 files changed, 124 insertions, 113 deletions
diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 987054b5c7..3d502a887b 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -6,6 +6,7 @@ set( changeset_wrapper.hpp config_loader.cpp config_loader.hpp + editable_data_source.hpp editable_feature_source.cpp editable_feature_source.hpp editor_config.cpp diff --git a/editor/editable_data_source.hpp b/editor/editable_data_source.hpp new file mode 100644 index 0000000000..fdb0841d2b --- /dev/null +++ b/editor/editable_data_source.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "editor/editable_feature_source.hpp" + +#include "indexer/data_source.hpp" + +using EditableDataSource = DataSourceImpl<EditableFeatureSource>; diff --git a/editor/editable_feature_source.cpp b/editor/editable_feature_source.cpp index 7b77a2cf8e..308324dc37 100644 --- a/editor/editable_feature_source.cpp +++ b/editor/editable_feature_source.cpp @@ -2,8 +2,6 @@ #include "editor/osm_editor.hpp" -namespace datasource -{ FeatureStatus EditableFeatureSource::GetFeatureStatus(uint32_t index) const { osm::Editor & editor = osm::Editor::Instance(); @@ -16,17 +14,16 @@ bool EditableFeatureSource::GetModifiedFeature(uint32_t index, FeatureType & fea return editor.GetEditedFeature(m_handle.GetId(), index, feature); } -void EditableFeatureSource::ForEachInRectAndScale(m2::RectD const & rect, int scale, - std::function<void(FeatureID const &)> const & fn) +void EditableFeatureSource::ForEachInRectAndScale( + m2::RectD const & rect, int scale, std::function<void(FeatureID const &)> const & fn) const { osm::Editor & editor = osm::Editor::Instance(); editor.ForEachFeatureInMwmRectAndScale(m_handle.GetId(), fn, rect, scale); } -void EditableFeatureSource::ForEachInRectAndScale(m2::RectD const & rect, int scale, - std::function<void(FeatureType &)> const & fn) +void EditableFeatureSource::ForEachInRectAndScale( + m2::RectD const & rect, int scale, std::function<void(FeatureType &)> const & fn) const { osm::Editor & editor = osm::Editor::Instance(); editor.ForEachFeatureInMwmRectAndScale(m_handle.GetId(), fn, rect, scale); } -} // namespace datasource diff --git a/editor/editable_feature_source.hpp b/editor/editable_feature_source.hpp index 018abbbbad..3dcb30e107 100644 --- a/editor/editable_feature_source.hpp +++ b/editor/editable_feature_source.hpp @@ -1,22 +1,24 @@ #pragma once +#include "indexer/feature.hpp" #include "indexer/feature_source.hpp" +#include "indexer/mwm_set.hpp" -namespace datasource -{ -class EditableFeatureSource : public FeatureSource +#include "geometry/rect2d.hpp" + +#include <cstdint> +#include <functional> + +class EditableFeatureSource final : public FeatureSource { public: - EditableFeatureSource(MwmSet::MwmHandle const & handle) : FeatureSource(handle) {} + explicit EditableFeatureSource(MwmSet::MwmHandle const & handle) : FeatureSource(handle) {} + // FeatureSource overrides: FeatureStatus GetFeatureStatus(uint32_t index) const override; - bool GetModifiedFeature(uint32_t index, FeatureType & feature) const override; - void ForEachInRectAndScale(m2::RectD const & rect, int scale, - std::function<void(FeatureID const &)> const & fn) override; + std::function<void(FeatureID const &)> const & fn) const override; void ForEachInRectAndScale(m2::RectD const & rect, int scale, - std::function<void(FeatureType &)> const & fn) override; - + std::function<void(FeatureType &)> const & fn) const override; }; // class EditableFeatureSource -} // namespace datasource diff --git a/editor/editor_tests/osm_editor_test.cpp b/editor/editor_tests/osm_editor_test.cpp index d4b7931ef3..acef4955e5 100644 --- a/editor/editor_tests/osm_editor_test.cpp +++ b/editor/editor_tests/osm_editor_test.cpp @@ -9,8 +9,9 @@ #include "indexer/classificator.hpp" #include "indexer/classificator_loader.hpp" +#include "indexer/data_source_helpers.hpp" +#include "indexer/feature_source.hpp" #include "indexer/ftypes_matcher.hpp" -#include "indexer/index_helpers.hpp" #include "platform/platform_tests_support/scoped_file.hpp" @@ -52,7 +53,7 @@ public: }; template <typename TFn> -void ForEachCafeAtPoint(Index & index, m2::PointD const & mercator, TFn && fn) +void ForEachCafeAtPoint(DataSourceBase & index, m2::PointD const & mercator, TFn && fn) { m2::RectD const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(mercator, 0.2 /* rect width */); @@ -346,29 +347,29 @@ void EditorTest::GetFeatureStatusTest() ForEachCafeAtPoint(m_index, m2::PointD(1.0, 1.0), [&editor](FeatureType & ft) { - TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), datasource::FeatureStatus::Untouched, ()); + TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), FeatureStatus::Untouched, ()); osm::EditableMapObject emo; FillEditableMapObject(editor, ft, emo); emo.SetBuildingLevels("1"); TEST_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::SavedSuccessfully, ()); - TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), datasource::FeatureStatus::Modified, ()); + TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), FeatureStatus::Modified, ()); editor.MarkFeatureAsObsolete(emo.GetID()); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Obsolete, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Obsolete, ()); }); ForEachCafeAtPoint(m_index, m2::PointD(2.0, 2.0), [&editor](FeatureType & ft) { - TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), datasource::FeatureStatus::Untouched, ()); + TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), FeatureStatus::Untouched, ()); editor.DeleteFeature(ft.GetID()); - TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), datasource::FeatureStatus::Deleted, ()); + TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), FeatureStatus::Deleted, ()); }); osm::EditableMapObject emo; CreateCafeAtPoint({1.5, 1.5}, mwmId, emo); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Created, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Created, ()); } void EditorTest::IsFeatureUploadedTest() @@ -420,12 +421,12 @@ void EditorTest::DeleteFeatureTest() editor.GetEditedFeature(emo.GetID().m_mwmId, emo.GetID().m_index, ft); editor.DeleteFeature(ft.GetID()); - TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), datasource::FeatureStatus::Untouched, ()); + TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), FeatureStatus::Untouched, ()); ForEachCafeAtPoint(m_index, m2::PointD(1.0, 1.0), [&editor](FeatureType & ft) { editor.DeleteFeature(ft.GetID()); - TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), datasource::FeatureStatus::Deleted, ()); + TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), FeatureStatus::Deleted, ()); }); } @@ -455,7 +456,7 @@ void EditorTest::GetFeaturesByStatusTest() { MwmSet::MwmId mwmId; - auto const features = editor.GetFeaturesByStatus(mwmId, datasource::FeatureStatus::Untouched); + auto const features = editor.GetFeaturesByStatus(mwmId, FeatureStatus::Untouched); TEST(features.empty(), ()); } @@ -500,10 +501,10 @@ void EditorTest::GetFeaturesByStatusTest() CreateCafeAtPoint({4.0, 4.0}, mwmId, emo); createdId = emo.GetID(); - auto const modified = editor.GetFeaturesByStatus(mwmId, datasource::FeatureStatus::Modified); - auto const deleted = editor.GetFeaturesByStatus(mwmId, datasource::FeatureStatus::Deleted); - auto const obsolete = editor.GetFeaturesByStatus(mwmId, datasource::FeatureStatus::Obsolete); - auto const created = editor.GetFeaturesByStatus(mwmId, datasource::FeatureStatus::Created); + auto const modified = editor.GetFeaturesByStatus(mwmId, FeatureStatus::Modified); + auto const deleted = editor.GetFeaturesByStatus(mwmId, FeatureStatus::Deleted); + auto const obsolete = editor.GetFeaturesByStatus(mwmId, FeatureStatus::Obsolete); + auto const created = editor.GetFeaturesByStatus(mwmId, FeatureStatus::Created); TEST_EQUAL(modified.size(), 1, ()); TEST_EQUAL(deleted.size(), 1, ()); @@ -811,14 +812,14 @@ void EditorTest::CreateNoteTest() auto notes = editor.m_notes->GetNotes(); TEST_NOT_EQUAL(notes.front().m_note.find(osm::Editor::kPlaceDoesNotExistMessage), string::npos, ()); - TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), datasource::FeatureStatus::Obsolete, ()); + TEST_EQUAL(editor.GetFeatureStatus(ft.GetID()), FeatureStatus::Obsolete, ()); }); ForEachCafeAtPoint(m_index, m2::PointD(2.0, 2.0), [&editor, &createAndCheckNote](FeatureType & ft) { createAndCheckNote(ft.GetID(), {2.0, 2.0}, osm::Editor::NoteProblemType::General); - TEST_NOT_EQUAL(editor.GetFeatureStatus(ft.GetID()), datasource::FeatureStatus::Obsolete, ()); + TEST_NOT_EQUAL(editor.GetFeatureStatus(ft.GetID()), FeatureStatus::Obsolete, ()); auto notes = editor.m_notes->GetNotes(); TEST_EQUAL(notes.front().m_note.find(osm::Editor::kPlaceDoesNotExistMessage), string::npos, ()); }); @@ -978,26 +979,26 @@ void EditorTest::SaveEditedFeatureTest() editor.CreatePoint(classif().GetTypeByPath({"amenity", "cafe"}), {4.0, 4.0}, mwmId, emo); emo.SetHouseNumber("12"); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Untouched, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Untouched, ()); TEST_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::SavedSuccessfully, ()); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Created, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Created, ()); TEST_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::NothingWasChanged, ()); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Created, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Created, ()); ForEachCafeAtPoint(m_index, m2::PointD(1.0, 1.0), [&editor](FeatureType & ft) { osm::EditableMapObject emo; FillEditableMapObject(editor, ft, emo); TEST_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::NothingWasChanged, ()); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Untouched, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Untouched, ()); emo.SetHouseNumber("4a"); TEST_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::SavedSuccessfully, ()); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Modified, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Modified, ()); TEST_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::NothingWasChanged, ()); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Modified, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Modified, ()); emo.SetHouseNumber(""); TEST_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::SavedSuccessfully, ()); - TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), datasource::FeatureStatus::Untouched, ()); + TEST_EQUAL(editor.GetFeatureStatus(emo.GetID()), FeatureStatus::Untouched, ()); }); } diff --git a/editor/editor_tests/osm_editor_test.hpp b/editor/editor_tests/osm_editor_test.hpp index 39817ab431..79d428c42f 100644 --- a/editor/editor_tests/osm_editor_test.hpp +++ b/editor/editor_tests/osm_editor_test.hpp @@ -1,15 +1,17 @@ #pragma once +#include "map/feature_vec_model.hpp" + #include "generator/generator_tests_support/test_feature.hpp" #include "generator/generator_tests_support/test_mwm_builder.hpp" -#include "platform/local_country_file_utils.hpp" - -#include "storage/country_info_getter.hpp" +#include "editor/editable_data_source.hpp" #include "indexer/mwm_set.hpp" -#include "map/feature_vec_model.hpp" +#include "storage/country_info_getter.hpp" + +#include "platform/local_country_file_utils.hpp" namespace editor { @@ -77,7 +79,7 @@ private: void Cleanup(platform::LocalCountryFile const & map); bool RemoveMwm(MwmSet::MwmId const & mwmId); - Index m_index; + EditableDataSource m_index; storage::CountryInfoGetterForTesting m_infoGetter; vector<platform::LocalCountryFile> m_mwmFiles; }; diff --git a/editor/edits_migration.cpp b/editor/edits_migration.cpp index 96a1c36278..9230d751e2 100644 --- a/editor/edits_migration.cpp +++ b/editor/edits_migration.cpp @@ -3,6 +3,7 @@ #include "editor/feature_matcher.hpp" #include "indexer/feature.hpp" +#include "indexer/feature_source.hpp" #include "geometry/algorithm.hpp" #include "geometry/mercator.hpp" @@ -16,13 +17,13 @@ namespace editor { FeatureID MigrateNodeFeatureIndex(osm::Editor::ForEachFeaturesNearByFn & forEach, XMLFeature const & xml, - datasource::FeatureStatus const featureStatus, + FeatureStatus const featureStatus, TGenerateIDFn const & generateID) { unique_ptr<FeatureType> feature; auto count = 0; forEach( - [&feature, &xml, &count](FeatureType const & ft) + [&feature, &count](FeatureType const & ft) { if (ft.GetFeatureType() != feature::GEOM_POINT) return; @@ -32,9 +33,9 @@ FeatureID MigrateNodeFeatureIndex(osm::Editor::ForEachFeaturesNearByFn & forEach }, MercatorBounds::FromLatLon(xml.GetCenter())); - if (!feature && featureStatus != datasource::FeatureStatus::Created) + if (!feature && featureStatus != FeatureStatus::Created) MYTHROW(MigrationError, ("No pointed features returned.")); - if (featureStatus == datasource::FeatureStatus::Created) + if (featureStatus == FeatureStatus::Created) return generateID(); if (count > 1) @@ -47,7 +48,7 @@ FeatureID MigrateNodeFeatureIndex(osm::Editor::ForEachFeaturesNearByFn & forEach FeatureID MigrateWayOrRelatonFeatureIndex( osm::Editor::ForEachFeaturesNearByFn & forEach, XMLFeature const & xml, - datasource::FeatureStatus const /* Unused for now (we don't create/delete area features)*/, + FeatureStatus const /* Unused for now (we don't create/delete area features)*/, TGenerateIDFn const & /*Unused for the same reason*/) { unique_ptr<FeatureType> feature; @@ -62,7 +63,7 @@ FeatureID MigrateWayOrRelatonFeatureIndex( auto const someFeaturePoint = geometry[0]; forEach( - [&feature, &xml, &geometry, &count, &bestScore](FeatureType const & ft) + [&feature, &geometry, &count, &bestScore](FeatureType const & ft) { if (ft.GetFeatureType() != feature::GEOM_AREA) return; @@ -104,7 +105,7 @@ FeatureID MigrateWayOrRelatonFeatureIndex( FeatureID MigrateFeatureIndex(osm::Editor::ForEachFeaturesNearByFn & forEach, XMLFeature const & xml, - datasource::FeatureStatus const featureStatus, + FeatureStatus const featureStatus, TGenerateIDFn const & generateID) { switch (xml.GetType()) diff --git a/editor/edits_migration.hpp b/editor/edits_migration.hpp index d78931a663..650c2a3db0 100644 --- a/editor/edits_migration.hpp +++ b/editor/edits_migration.hpp @@ -4,6 +4,7 @@ #include "editor/xml_feature.hpp" #include "indexer/feature_decl.hpp" +#include "indexer/feature_source.hpp" #include "base/exception.hpp" @@ -19,6 +20,6 @@ using TGenerateIDFn = function<FeatureID()>; /// of a found feature, thows MigrationError if migration fails. FeatureID MigrateFeatureIndex(osm::Editor::ForEachFeaturesNearByFn & forEach, XMLFeature const & xml, - datasource::FeatureStatus const featureStatus, + FeatureStatus const featureStatus, TGenerateIDFn const & generateID); } // namespace editor diff --git a/editor/osm_editor.cpp b/editor/osm_editor.cpp index 5c9d427e5b..c1f1c7aa1c 100644 --- a/editor/osm_editor.cpp +++ b/editor/osm_editor.cpp @@ -8,14 +8,15 @@ #include "indexer/categories_holder.hpp" #include "indexer/classificator.hpp" +#include "indexer/data_source_helpers.hpp" #include "indexer/fake_feature_ids.hpp" #include "indexer/feature_algo.hpp" #include "indexer/feature_decl.hpp" #include "indexer/feature_impl.hpp" #include "indexer/feature_meta.hpp" +#include "indexer/feature_source.hpp" #include "indexer/ftypes_matcher.hpp" -#include "indexer/index.hpp" -#include "indexer/index_helpers.hpp" +#include "indexer/mwm_set.hpp" #include "platform/local_country_file_utils.hpp" #include "platform/platform.hpp" @@ -67,22 +68,22 @@ constexpr char const * kMatchedFeatureIsEmpty = "Matched feature has no tags"; struct XmlSection { - XmlSection(datasource::FeatureStatus status, std::string const & sectionName) + XmlSection(FeatureStatus status, std::string const & sectionName) : m_status(status) , m_sectionName(sectionName) { } - datasource::FeatureStatus m_status = datasource::FeatureStatus::Untouched; + FeatureStatus m_status = FeatureStatus::Untouched; std::string m_sectionName; }; array<XmlSection, 4> const kXmlSections = {{ - {datasource::FeatureStatus::Deleted, kDeleteSection}, - {datasource::FeatureStatus::Modified, kModifySection}, - {datasource::FeatureStatus::Obsolete, kObsoleteSection}, - {datasource::FeatureStatus::Created, kCreateSection} + {FeatureStatus::Deleted, kDeleteSection}, + {FeatureStatus::Modified, kModifySection}, + {FeatureStatus::Obsolete, kObsoleteSection}, + {FeatureStatus::Created, kCreateSection} }}; struct LogHelper @@ -95,15 +96,15 @@ struct LogHelper m_deleted, "deleted and", m_obsolete, "obsolete features.")); } - void OnStatus(datasource::FeatureStatus status) + void OnStatus(FeatureStatus status) { switch (status) { - case datasource::FeatureStatus::Deleted: ++m_deleted; break; - case datasource::FeatureStatus::Modified: ++m_modified; break; - case datasource::FeatureStatus::Obsolete: ++m_obsolete; break; - case datasource::FeatureStatus::Created: ++m_created; break; - case datasource::FeatureStatus::Untouched: ASSERT(false, ()); + case FeatureStatus::Deleted: ++m_deleted; break; + case FeatureStatus::Modified: ++m_modified; break; + case FeatureStatus::Obsolete: ++m_obsolete; break; + case FeatureStatus::Created: ++m_created; break; + case FeatureStatus::Untouched: ASSERT(false, ()); } } @@ -283,11 +284,11 @@ bool Editor::Save() const } switch (fti.m_status) { - case datasource::FeatureStatus::Deleted: VERIFY(xf.AttachToParentNode(deleted), ()); break; - case datasource::FeatureStatus::Modified: VERIFY(xf.AttachToParentNode(modified), ()); break; - case datasource::FeatureStatus::Created: VERIFY(xf.AttachToParentNode(created), ()); break; - case datasource::FeatureStatus::Obsolete: VERIFY(xf.AttachToParentNode(obsolete), ()); break; - case datasource::FeatureStatus::Untouched: CHECK(false, ("Not edited features shouldn't be here.")); + case FeatureStatus::Deleted: VERIFY(xf.AttachToParentNode(deleted), ()); break; + case FeatureStatus::Modified: VERIFY(xf.AttachToParentNode(modified), ()); break; + case FeatureStatus::Created: VERIFY(xf.AttachToParentNode(created), ()); break; + case FeatureStatus::Obsolete: VERIFY(xf.AttachToParentNode(obsolete), ()); break; + case FeatureStatus::Untouched: CHECK(false, ("Not edited features shouldn't be here.")); } } } @@ -321,20 +322,20 @@ void Editor::OnMapDeregistered(platform::LocalCountryFile const & localFile) } } -datasource::FeatureStatus Editor::GetFeatureStatus(MwmSet::MwmId const & mwmId, uint32_t index) const +FeatureStatus Editor::GetFeatureStatus(MwmSet::MwmId const & mwmId, uint32_t index) const { // Most popular case optimization. if (m_features.empty()) - return datasource::FeatureStatus::Untouched; + return FeatureStatus::Untouched; auto const * featureInfo = GetFeatureTypeInfo(mwmId, index); if (featureInfo == nullptr) - return datasource::FeatureStatus::Untouched; + return FeatureStatus::Untouched; return featureInfo->m_status; } -datasource::FeatureStatus Editor::GetFeatureStatus(FeatureID const & fid) const +FeatureStatus Editor::GetFeatureStatus(FeatureID const & fid) const { return GetFeatureStatus(fid.m_mwmId, fid.m_index); } @@ -352,14 +353,14 @@ void Editor::DeleteFeature(FeatureID const & fid) { auto const f = mwm->second.find(fid.m_index); // Created feature is deleted by removing all traces of it. - if (f != mwm->second.end() && f->second.m_status == datasource::FeatureStatus::Created) + if (f != mwm->second.end() && f->second.m_status == FeatureStatus::Created) { mwm->second.erase(f); return; } } - MarkFeatureWithStatus(fid, datasource::FeatureStatus::Deleted); + MarkFeatureWithStatus(fid, FeatureStatus::Deleted); // TODO(AlexZ): Synchronize Save call/make it on a separate thread. Save(); @@ -390,16 +391,16 @@ Editor::SaveResult Editor::SaveEditedFeature(EditableMapObject const & emo) FeatureTypeInfo fti; auto const featureStatus = GetFeatureStatus(fid.m_mwmId, fid.m_index); - ASSERT_NOT_EQUAL(featureStatus, datasource::FeatureStatus::Obsolete, ("Obsolete feature cannot be modified.")); - ASSERT_NOT_EQUAL(featureStatus, datasource::FeatureStatus::Deleted, ("Unexpected feature status.")); + ASSERT_NOT_EQUAL(featureStatus, FeatureStatus::Obsolete, ("Obsolete feature cannot be modified.")); + ASSERT_NOT_EQUAL(featureStatus, FeatureStatus::Deleted, ("Unexpected feature status.")); bool const wasCreatedByUser = IsCreatedFeature(fid); if (wasCreatedByUser) { - fti.m_status = datasource::FeatureStatus::Created; + fti.m_status = FeatureStatus::Created; fti.m_feature.ReplaceBy(emo); - if (featureStatus == datasource::FeatureStatus::Created) + if (featureStatus == FeatureStatus::Created) { auto const & editedFeatureInfo = m_features[fid.m_mwmId][fid.m_index]; if (AreFeaturesEqualButStreet(fti.m_feature, editedFeatureInfo.m_feature) && @@ -419,7 +420,7 @@ Editor::SaveResult Editor::SaveEditedFeature(EditableMapObject const & emo) return SaveResult::SavingError; } - fti.m_feature = featureStatus == datasource::FeatureStatus::Untouched + fti.m_feature = featureStatus == FeatureStatus::Untouched ? *originalFeaturePtr : m_features[fid.m_mwmId][fid.m_index].m_feature; fti.m_feature.ReplaceBy(emo); @@ -427,7 +428,7 @@ Editor::SaveResult Editor::SaveEditedFeature(EditableMapObject const & emo) AreFeaturesEqualButStreet(fti.m_feature, *originalFeaturePtr) && emo.GetStreet().m_defaultName == GetOriginalFeatureStreet(fti.m_feature); - if (featureStatus != datasource::FeatureStatus::Untouched) + if (featureStatus != FeatureStatus::Untouched) { // A feature was modified and equals to the one in editor. auto const & editedFeatureInfo = m_features[fid.m_mwmId][fid.m_index]; @@ -459,7 +460,7 @@ Editor::SaveResult Editor::SaveEditedFeature(EditableMapObject const & emo) return NothingWasChanged; } - fti.m_status = datasource::FeatureStatus::Modified; + fti.m_status = FeatureStatus::Modified; } // TODO: What if local client time is absolutely wrong? @@ -498,7 +499,7 @@ void Editor::ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id, for (auto const & index : mwmFound->second) { FeatureTypeInfo const & ftInfo = index.second; - if (ftInfo.m_status == datasource::FeatureStatus::Created && + if (ftInfo.m_status == FeatureStatus::Created && rect.IsPointInside(ftInfo.m_feature.GetCenter())) f(FeatureID(id, index.first)); } @@ -518,7 +519,7 @@ void Editor::ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id, for (auto & index : mwmFound->second) { FeatureTypeInfo & ftInfo = index.second; - if (ftInfo.m_status == datasource::FeatureStatus::Created && + if (ftInfo.m_status == FeatureStatus::Created && rect.IsPointInside(ftInfo.m_feature.GetCenter())) f(ftInfo.m_feature); } @@ -550,7 +551,7 @@ bool Editor::GetEditedFeatureStreet(FeatureID const & fid, string & outFeatureSt return true; } -vector<uint32_t> Editor::GetFeaturesByStatus(MwmSet::MwmId const & mwmId, datasource::FeatureStatus status) const +vector<uint32_t> Editor::GetFeaturesByStatus(MwmSet::MwmId const & mwmId, FeatureStatus status) const { vector<uint32_t> features; auto const matchedMwm = m_features.find(mwmId); @@ -570,14 +571,14 @@ EditableProperties Editor::GetEditableProperties(FeatureType const & feature) co ASSERT(version::IsSingleMwm(feature.GetID().m_mwmId.GetInfo()->m_version.GetVersion()), ("Edit mode should be available only on new data")); - ASSERT(GetFeatureStatus(feature.GetID()) != datasource::FeatureStatus::Obsolete, + ASSERT(GetFeatureStatus(feature.GetID()) != FeatureStatus::Obsolete, ("Edit mode should not be available on obsolete features")); // TODO(mgsergio): Check if feature is in the area where editing is disabled in the config. auto editableProperties = GetEditablePropertiesForTypes(feature::TypesHolder(feature)); // Disable opening hours editing if opening hours cannot be parsed. - if (GetFeatureStatus(feature.GetID()) != datasource::FeatureStatus::Created) + if (GetFeatureStatus(feature.GetID()) != FeatureStatus::Created) { auto const originalFeaturePtr = GetOriginalFeature(feature.GetID()); if (!originalFeaturePtr) @@ -683,9 +684,9 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset { switch (fti.m_status) { - case datasource::FeatureStatus::Untouched: CHECK(false, ("It's impossible.")); continue; - case datasource::FeatureStatus::Obsolete: continue; // Obsolete features will be deleted by OSMers. - case datasource::FeatureStatus::Created: + case FeatureStatus::Untouched: CHECK(false, ("It's impossible.")); continue; + case FeatureStatus::Obsolete: continue; // Obsolete features will be deleted by OSMers. + case FeatureStatus::Created: { XMLFeature feature = editor::ToXML(fti.m_feature, true); if (!fti.m_street.empty()) @@ -732,7 +733,7 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset } break; - case datasource::FeatureStatus::Modified: + case FeatureStatus::Modified: { // Do not serialize feature's type to avoid breaking OSM data. // TODO: Implement correct types matching when we support modifying existing feature types. @@ -768,7 +769,7 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset } break; - case datasource::FeatureStatus::Deleted: + case FeatureStatus::Deleted: auto const originalFeaturePtr = GetOriginalFeature(fti.m_feature.GetID()); if (!originalFeaturePtr) { @@ -861,10 +862,10 @@ void Editor::SaveUploadedInformation(FeatureTypeInfo const & fromUploader) Save(); } -bool Editor::FillFeatureInfo(datasource::FeatureStatus status, XMLFeature const & xml, FeatureID const & fid, +bool Editor::FillFeatureInfo(FeatureStatus status, XMLFeature const & xml, FeatureID const & fid, FeatureTypeInfo & fti) const { - if (status == datasource::FeatureStatus::Created) + if (status == FeatureStatus::Created) { editor::FromXML(xml, fti.m_feature); } @@ -953,13 +954,13 @@ void Editor::Invalidate() bool Editor::MarkFeatureAsObsolete(FeatureID const & fid) { auto const featureStatus = GetFeatureStatus(fid); - if (featureStatus != datasource::FeatureStatus::Untouched && featureStatus != datasource::FeatureStatus::Modified) + if (featureStatus != FeatureStatus::Untouched && featureStatus != FeatureStatus::Modified) { ASSERT(false, ("Only untouched and modified features can be made obsolete")); return false; } - MarkFeatureWithStatus(fid, datasource::FeatureStatus::Obsolete); + MarkFeatureWithStatus(fid, FeatureStatus::Obsolete); Invalidate(); return Save(); @@ -1013,7 +1014,7 @@ FeatureID Editor::GenerateNewFeatureId(MwmSet::MwmId const & id) const // Scan all already created features and choose next available ID. for (auto const & feature : found->second) { - if (feature.second.m_status == datasource::FeatureStatus::Created && featureIndex <= feature.first) + if (feature.second.m_status == FeatureStatus::Created && featureIndex <= feature.first) featureIndex = feature.first + 1; } } @@ -1055,7 +1056,7 @@ void Editor::CreateNote(ms::LatLon const & latLon, FeatureID const & fid, case NoteProblemType::PlaceDoesNotExist: { sstr << kPlaceDoesNotExistMessage << endl; - auto const isCreated = GetFeatureStatus(fid) == datasource::FeatureStatus::Created; + auto const isCreated = GetFeatureStatus(fid) == FeatureStatus::Created; auto const createdAndUploaded = (isCreated && IsFeatureUploaded(fid.m_mwmId, fid.m_index)); CHECK(!isCreated || createdAndUploaded, ()); @@ -1093,7 +1094,7 @@ void Editor::UploadNotes(string const & key, string const & secret) m_notes->Upload(OsmOAuth::ServerAuth({key, secret})); } -void Editor::MarkFeatureWithStatus(FeatureID const & fid, datasource::FeatureStatus status) +void Editor::MarkFeatureWithStatus(FeatureID const & fid, FeatureStatus status) { auto & fti = m_features[fid.m_mwmId][fid.m_index]; @@ -1152,7 +1153,7 @@ void Editor::ForEachFeatureAtPoint(FeatureTypeFn && fn, m2::PointD const & point } FeatureID Editor::GetFeatureIdByXmlFeature(XMLFeature const & xml, MwmSet::MwmId const & mwmId, - datasource::FeatureStatus status, bool needMigrate) const + FeatureStatus status, bool needMigrate) const { ForEachFeaturesNearByFn forEach = [this](FeatureTypeFn && fn, m2::PointD const & point) { diff --git a/editor/osm_editor.hpp b/editor/osm_editor.hpp index ba03dd0d65..da215aa9d2 100644 --- a/editor/osm_editor.hpp +++ b/editor/osm_editor.hpp @@ -36,8 +36,6 @@ namespace editor class XMLFeature; } -class Index; - namespace osm { class Editor final : public MwmSet::Observer @@ -108,8 +106,8 @@ public: // TODO(mgsergio): Unify feature functions signatures. /// Easy way to check if a feature was deleted, modified, created or not changed at all. - datasource::FeatureStatus GetFeatureStatus(MwmSet::MwmId const & mwmId, uint32_t index) const; - datasource::FeatureStatus GetFeatureStatus(FeatureID const & fid) const; + FeatureStatus GetFeatureStatus(MwmSet::MwmId const & mwmId, uint32_t index) const; + FeatureStatus GetFeatureStatus(FeatureID const & fid) const; /// @returns true if a feature was uploaded to osm. bool IsFeatureUploaded(MwmSet::MwmId const & mwmId, uint32_t index) const; @@ -127,7 +125,7 @@ public: bool GetEditedFeatureStreet(FeatureID const & fid, string & outFeatureStreet) const; /// @returns sorted features indices with specified status. - vector<uint32_t> GetFeaturesByStatus(MwmSet::MwmId const & mwmId, datasource::FeatureStatus status) const; + vector<uint32_t> GetFeaturesByStatus(MwmSet::MwmId const & mwmId, FeatureStatus status) const; enum SaveResult { @@ -207,7 +205,7 @@ private: struct FeatureTypeInfo { - datasource::FeatureStatus m_status; + FeatureStatus m_status; // TODO(AlexZ): Integrate EditableMapObject class into an editor instead of FeatureType. FeatureType m_feature; /// If not empty contains Feature's addr:street, edited by user. @@ -219,14 +217,14 @@ private: string m_uploadError; }; - bool FillFeatureInfo(datasource::FeatureStatus status, editor::XMLFeature const & xml, FeatureID const & fid, + bool FillFeatureInfo(FeatureStatus status, editor::XMLFeature const & xml, FeatureID const & fid, FeatureTypeInfo & fti) const; /// @returns pointer to m_features[id][index] if exists, nullptr otherwise. FeatureTypeInfo const * GetFeatureTypeInfo(MwmSet::MwmId const & mwmId, uint32_t index) const; FeatureTypeInfo * GetFeatureTypeInfo(MwmSet::MwmId const & mwmId, uint32_t index); void SaveUploadedInformation(FeatureTypeInfo const & fromUploader); - void MarkFeatureWithStatus(FeatureID const & fid, datasource::FeatureStatus status); + void MarkFeatureWithStatus(FeatureID const & fid, FeatureStatus status); // These methods are just checked wrappers around Delegate. MwmSet::MwmId GetMwmIdByMapName(string const & name); @@ -234,7 +232,7 @@ private: string GetOriginalFeatureStreet(FeatureType & ft) const; void ForEachFeatureAtPoint(FeatureTypeFn && fn, m2::PointD const & point) const; FeatureID GetFeatureIdByXmlFeature(editor::XMLFeature const & xml, MwmSet::MwmId const & mwmId, - datasource::FeatureStatus status, bool needMigrate) const; + FeatureStatus status, bool needMigrate) const; void LoadMwmEdits(pugi::xml_node const & mwm, MwmSet::MwmId const & mwmId, bool needMigrate); // TODO(AlexZ): Synchronize multithread access. |