diff --git a/editor/editable_feature_source.cpp b/editor/editable_feature_source.cpp index d880a06833..2ad4d63377 100644 --- a/editor/editable_feature_source.cpp +++ b/editor/editable_feature_source.cpp @@ -2,6 +2,8 @@ #include "editor/osm_editor.hpp" +using namespace std; + FeatureStatus EditableFeatureSource::GetFeatureStatus(uint32_t index) const { osm::Editor & editor = osm::Editor::Instance(); @@ -11,11 +13,14 @@ FeatureStatus EditableFeatureSource::GetFeatureStatus(uint32_t index) const unique_ptr EditableFeatureSource::GetModifiedFeature(uint32_t index) const { osm::Editor & editor = osm::Editor::Instance(); - return editor.GetEditedFeature(FeatureID(m_handle.GetId(), index)); + auto const emo = editor.GetEditedFeature(FeatureID(m_handle.GetId(), index)); + if (emo) + return make_unique(*emo); + return {}; } void EditableFeatureSource::ForEachAdditionalFeature(m2::RectD const & rect, int scale, - std::function const & fn) const + function const & fn) const { osm::Editor & editor = osm::Editor::Instance(); editor.ForEachCreatedFeature(m_handle.GetId(), fn, rect, scale); diff --git a/editor/editor_tests/osm_editor_test.cpp b/editor/editor_tests/osm_editor_test.cpp index 135517761e..0d0b283f0e 100644 --- a/editor/editor_tests/osm_editor_test.cpp +++ b/editor/editor_tests/osm_editor_test.cpp @@ -263,15 +263,12 @@ void EditorTest::GetEditedFeatureTest() SetBuildingLevelsToOne(ft); - auto featureType = editor.GetEditedFeature(ft.GetID()); - TEST(featureType, ()); + auto savedEmo = editor.GetEditedFeature(ft.GetID()); + TEST(savedEmo, ()); - osm::EditableMapObject savedEmo; - FillEditableMapObject(editor, *featureType, savedEmo); + TEST_EQUAL(savedEmo->GetBuildingLevels(), "1", ()); - TEST_EQUAL(savedEmo.GetBuildingLevels(), "1", ()); - - TEST_EQUAL(ft.GetID(), featureType->GetID(), ()); + TEST_EQUAL(ft.GetID(), savedEmo->GetID(), ()); }); } diff --git a/editor/osm_editor.cpp b/editor/osm_editor.cpp index f08fb47b57..78f122f1b3 100644 --- a/editor/osm_editor.cpp +++ b/editor/osm_editor.cpp @@ -516,14 +516,14 @@ void Editor::ForEachCreatedFeature(MwmSet::MwmId const & id, FeatureIndexFunctor } } -unique_ptr Editor::GetEditedFeature(FeatureID const & fid) const +boost::optional Editor::GetEditedFeature(FeatureID const & fid) const { auto const features = m_features.Get(); auto const * featureInfo = GetFeatureTypeInfo(*features, fid.m_mwmId, fid.m_index); if (featureInfo == nullptr) return {}; - return make_unique(featureInfo->m_object); + return featureInfo->m_object; } bool Editor::GetEditedFeatureStreet(FeatureID const & fid, string & outFeatureStreet) const diff --git a/editor/osm_editor.hpp b/editor/osm_editor.hpp index 4c9101502d..e0264e323d 100644 --- a/editor/osm_editor.hpp +++ b/editor/osm_editor.hpp @@ -28,6 +28,8 @@ #include #include +#include + namespace editor { namespace testing @@ -142,8 +144,8 @@ public: /// Marks feature as "deleted" from MwM file. void DeleteFeature(FeatureID const & fid); - /// @returns nullptr if feature wasn't edited. - std::unique_ptr GetEditedFeature(FeatureID const & fid) const; + /// @returns empty object if feature wasn't edited. + boost::optional GetEditedFeature(FeatureID const & fid) const; /// @returns false if feature wasn't edited. /// @param outFeatureStreet is valid only if true was returned. diff --git a/search/features_layer_matcher.cpp b/search/features_layer_matcher.cpp index 050d4c22c5..e9fc383865 100644 --- a/search/features_layer_matcher.cpp +++ b/search/features_layer_matcher.cpp @@ -3,6 +3,8 @@ #include "search/house_to_street_table.hpp" #include "search/reverse_geocoder.hpp" +#include "editor/osm_editor.hpp" + #include "indexer/scales.hpp" #include "base/assert.hpp" diff --git a/search/mwm_context.cpp b/search/mwm_context.cpp index b42726f078..7594565927 100644 --- a/search/mwm_context.cpp +++ b/search/mwm_context.cpp @@ -19,6 +19,7 @@ MwmContext::MwmContext(MwmSet::MwmHandle handle) , m_vector(m_value.m_cont, m_value.GetHeader(), m_value.m_table.get()) , m_index(m_value.m_cont.GetReader(INDEX_FILE_TAG), m_value.m_factory) , m_centers(m_value) + , m_editableSource(m_handle) { } @@ -32,11 +33,12 @@ std::unique_ptr MwmContext::GetFeature(uint32_t index) const return ft; case FeatureStatus::Modified: case FeatureStatus::Created: - ft = osm::Editor::Instance().GetEditedFeature(FeatureID(GetId(), index)); + ft = m_editableSource.GetModifiedFeature(index); CHECK(ft, ()); return ft; case FeatureStatus::Untouched: - ft = m_vector.GetByIndex(index); + auto ft = m_vector.GetByIndex(index); + CHECK(ft, ()); ft->SetID(FeatureID(GetId(), index)); return ft; } diff --git a/search/mwm_context.hpp b/search/mwm_context.hpp index 1489e04ee2..5857342ccd 100644 --- a/search/mwm_context.hpp +++ b/search/mwm_context.hpp @@ -3,7 +3,7 @@ #include "search/house_to_street_table.hpp" #include "search/lazy_centers_table.hpp" -#include "editor/osm_editor.hpp" +#include "editor/editable_feature_source.hpp" #include "indexer/feature_covering.hpp" #include "indexer/feature_source.hpp" @@ -84,7 +84,7 @@ public: private: FeatureStatus GetEditedStatus(uint32_t index) const { - return osm::Editor::Instance().GetFeatureStatus(GetId(), index); + return m_editableSource.GetFeatureStatus(index); } template @@ -103,6 +103,7 @@ private: FeaturesVector m_vector; ScaleIndex m_index; LazyCentersTable m_centers; + EditableFeatureSource m_editableSource; DISALLOW_COPY_AND_MOVE(MwmContext); }; diff --git a/search/retrieval.cpp b/search/retrieval.cpp index 0116b51361..42817a8149 100644 --- a/search/retrieval.cpp +++ b/search/retrieval.cpp @@ -8,6 +8,8 @@ #include "search/search_trie.hpp" #include "search/token_slice.hpp" +#include "editor/osm_editor.hpp" + #include "indexer/classificator.hpp" #include "indexer/feature.hpp" #include "indexer/feature_algo.hpp" @@ -98,9 +100,10 @@ private: auto & editor = Editor::Instance(); for (auto const index : features) { - auto ft = editor.GetEditedFeature(FeatureID(m_id, index)); - CHECK(ft, ()); - fn(*ft, index); + auto emo = editor.GetEditedFeature(FeatureID(m_id, index)); + CHECK(emo, ()); + FeatureType ft(*emo); + fn(ft, index); } } diff --git a/search/reverse_geocoder.cpp b/search/reverse_geocoder.cpp index a4c453fb8c..d9fb8943c5 100644 --- a/search/reverse_geocoder.cpp +++ b/search/reverse_geocoder.cpp @@ -1,9 +1,10 @@ -#include "reverse_geocoder.hpp" +#include "search/reverse_geocoder.hpp" #include "search/mwm_context.hpp" -#include "indexer/data_source.hpp" +#include "editor/osm_editor.hpp" +#include "indexer/data_source.hpp" #include "indexer/fake_feature_ids.hpp" #include "indexer/feature.hpp" #include "indexer/feature_algo.hpp"