mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -24,9 +24,9 @@
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
|
||||
#include "3party/opening_hours/opening_hours.hpp"
|
||||
#include <pugixml.hpp>
|
||||
#include <utility>
|
||||
#include "3party/opening_hours/opening_hours.hpp"
|
||||
|
||||
namespace osm
|
||||
{
|
||||
@@ -54,21 +54,16 @@ constexpr char const * kMatchedFeatureIsEmpty = "Matched feature has no tags";
|
||||
|
||||
struct XmlSection
|
||||
{
|
||||
constexpr XmlSection(FeatureStatus status, char const * sectionName)
|
||||
: m_status(status), m_sectionName(sectionName)
|
||||
{
|
||||
}
|
||||
constexpr XmlSection(FeatureStatus status, char const * sectionName) : m_status(status), m_sectionName(sectionName) {}
|
||||
|
||||
FeatureStatus m_status = FeatureStatus::Untouched;
|
||||
char const * m_sectionName;
|
||||
};
|
||||
|
||||
std::array<XmlSection, 4> constexpr kXmlSections = {
|
||||
{{FeatureStatus::Deleted, kDeleteSection},
|
||||
{FeatureStatus::Modified, kModifySection},
|
||||
{FeatureStatus::Obsolete, kObsoleteSection},
|
||||
{FeatureStatus::Created, kCreateSection}}
|
||||
};
|
||||
std::array<XmlSection, 4> constexpr kXmlSections = {{{FeatureStatus::Deleted, kDeleteSection},
|
||||
{FeatureStatus::Modified, kModifySection},
|
||||
{FeatureStatus::Obsolete, kObsoleteSection},
|
||||
{FeatureStatus::Created, kCreateSection}}};
|
||||
|
||||
struct LogHelper
|
||||
{
|
||||
@@ -76,8 +71,8 @@ struct LogHelper
|
||||
|
||||
~LogHelper()
|
||||
{
|
||||
LOG(LINFO, ("For", m_mwmId, ". Was loaded", m_modified, "modified,", m_created, "created,",
|
||||
m_deleted, "deleted and", m_obsolete, "obsolete features."));
|
||||
LOG(LINFO, ("For", m_mwmId, ". Was loaded", m_modified, "modified,", m_created, "created,", m_deleted,
|
||||
"deleted and", m_obsolete, "obsolete features."));
|
||||
}
|
||||
|
||||
void OnStatus(FeatureStatus status)
|
||||
@@ -101,14 +96,12 @@ struct LogHelper
|
||||
|
||||
bool NeedsUpload(string const & uploadStatus)
|
||||
{
|
||||
return uploadStatus != kUploaded && uploadStatus != kDeletedFromOSMServer &&
|
||||
uploadStatus != kMatchedFeatureIsEmpty;
|
||||
return uploadStatus != kUploaded && uploadStatus != kDeletedFromOSMServer && uploadStatus != kMatchedFeatureIsEmpty;
|
||||
}
|
||||
|
||||
XMLFeature GetMatchingFeatureFromOSM(osm::ChangesetWrapper & cw, const osm::EditableMapObject & o)
|
||||
XMLFeature GetMatchingFeatureFromOSM(osm::ChangesetWrapper & cw, osm::EditableMapObject const & o)
|
||||
{
|
||||
ASSERT_NOT_EQUAL(o.GetGeomType(), feature::GeomType::Line,
|
||||
("Line features are not supported yet."));
|
||||
ASSERT_NOT_EQUAL(o.GetGeomType(), feature::GeomType::Line, ("Line features are not supported yet."));
|
||||
if (o.GetGeomType() == feature::GeomType::Point)
|
||||
return cw.GetMatchingNodeFeatureFromOSM(o.GetMercator());
|
||||
|
||||
@@ -133,10 +126,7 @@ bool IsObsolete(editor::XMLFeature const & xml, FeatureID const & fid)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Editor::Editor()
|
||||
: m_configLoader(m_config)
|
||||
, m_notes(editor::Notes::MakeNotes())
|
||||
, m_isUploadingNow(false)
|
||||
Editor::Editor() : m_configLoader(m_config), m_notes(editor::Notes::MakeNotes()), m_isUploadingNow(false)
|
||||
{
|
||||
SetDefaultStorage();
|
||||
}
|
||||
@@ -147,7 +137,10 @@ Editor & Editor::Instance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Editor::SetDefaultStorage() { m_storage = std::make_unique<editor::LocalStorage>(); }
|
||||
void Editor::SetDefaultStorage()
|
||||
{
|
||||
m_storage = std::make_unique<editor::LocalStorage>();
|
||||
}
|
||||
|
||||
void Editor::LoadEdits()
|
||||
{
|
||||
@@ -222,8 +215,7 @@ bool Editor::Save(FeaturesContainer const & features) const
|
||||
FeatureTypeInfo const & fti = index.second;
|
||||
// TODO: Do we really need to serialize deleted features in full details? Looks like mwm ID
|
||||
// and meta fields are enough.
|
||||
XMLFeature xf =
|
||||
editor::ToXML(fti.m_object, true /* type serializing helps during migration */);
|
||||
XMLFeature xf = editor::ToXML(fti.m_object, true /* type serializing helps during migration */);
|
||||
xf.SetEditJournal(fti.m_object.GetJournal());
|
||||
xf.SetMWMFeatureIndex(index.first);
|
||||
if (!fti.m_street.empty())
|
||||
@@ -375,9 +367,8 @@ Editor::SaveResult Editor::SaveEditedFeature(EditableMapObject const & emo)
|
||||
return SaveResult::SavingError;
|
||||
}
|
||||
fti.m_object = emo;
|
||||
bool const sameAsInMWM =
|
||||
AreObjectsEqualIgnoringStreet(fti.m_object, *originalObjectPtr) &&
|
||||
emo.GetStreet().m_defaultName == GetOriginalFeatureStreet(fti.m_object.GetID());
|
||||
bool const sameAsInMWM = AreObjectsEqualIgnoringStreet(fti.m_object, *originalObjectPtr) &&
|
||||
emo.GetStreet().m_defaultName == GetOriginalFeatureStreet(fti.m_object.GetID());
|
||||
|
||||
if (featureStatus != FeatureStatus::Untouched)
|
||||
{
|
||||
@@ -440,8 +431,8 @@ bool Editor::RollBackChanges(FeatureID const & fid)
|
||||
return RemoveFeature(fid);
|
||||
}
|
||||
|
||||
void Editor::ForEachCreatedFeature(MwmId const & id, FeatureIndexFunctor const & f,
|
||||
m2::RectD const & rect, int /*scale*/) const
|
||||
void Editor::ForEachCreatedFeature(MwmId const & id, FeatureIndexFunctor const & f, m2::RectD const & rect,
|
||||
int /*scale*/) const
|
||||
{
|
||||
auto const features = m_features.Get();
|
||||
|
||||
@@ -492,8 +483,7 @@ bool Editor::GetEditedFeatureStreet(FeatureID const & fid, string & outFeatureSt
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> Editor::GetFeaturesByStatus(MwmId const & mwmId,
|
||||
FeatureStatus status) const
|
||||
std::vector<uint32_t> Editor::GetFeaturesByStatus(MwmId const & mwmId, FeatureStatus status) const
|
||||
{
|
||||
auto const features = m_features.Get();
|
||||
|
||||
@@ -503,10 +493,8 @@ std::vector<uint32_t> Editor::GetFeaturesByStatus(MwmId const & mwmId,
|
||||
return result;
|
||||
|
||||
for (auto const & index : matchedMwm->second)
|
||||
{
|
||||
if (index.second.m_status == status)
|
||||
result.push_back(index.first);
|
||||
}
|
||||
std::sort(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
@@ -518,8 +506,7 @@ EditableProperties Editor::GetEditableProperties(FeatureType & feature) const
|
||||
auto const & fid = feature.GetID();
|
||||
auto const featureStatus = GetFeatureStatusImpl(*features, fid.m_mwmId, fid.m_index);
|
||||
|
||||
ASSERT(featureStatus != FeatureStatus::Obsolete,
|
||||
("Edit mode should not be available on obsolete features"));
|
||||
ASSERT(featureStatus != 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));
|
||||
@@ -552,8 +539,8 @@ EditableProperties Editor::GetEditablePropertiesForTypes(feature::TypesHolder co
|
||||
editor::TypeAggregatedDescription desc;
|
||||
if (m_config.Get()->GetTypeDescription(types.ToObjectNames(), desc))
|
||||
{
|
||||
return { std::move(desc.m_editableFields), desc.IsNameEditable(),
|
||||
desc.IsAddressEditable(), desc.IsCuisineEditable() };
|
||||
return {std::move(desc.m_editableFields), desc.IsNameEditable(), desc.IsAddressEditable(),
|
||||
desc.IsCuisineEditable()};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -578,16 +565,13 @@ bool Editor::HaveMapEditsToUpload(MwmId const & mwmId) const
|
||||
if (found != features->cend())
|
||||
{
|
||||
for (auto const & index : found->second)
|
||||
{
|
||||
if (NeedsUpload(index.second.m_uploadStatus))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Editor::UploadChanges(string const & oauthToken, ChangesetTags tags,
|
||||
FinishUploadCallback callback)
|
||||
void Editor::UploadChanges(string const & oauthToken, ChangesetTags tags, FinishUploadCallback callback)
|
||||
{
|
||||
if (m_notes->NotUploadedNotesCount())
|
||||
m_notes->Upload(OsmOAuth::ServerAuth(oauthToken));
|
||||
@@ -625,7 +609,8 @@ void Editor::UploadChanges(string const & oauthToken, ChangesetTags tags,
|
||||
|
||||
// Don't use new editor for Legacy Objects
|
||||
auto const & journalHistory = fti.m_object.GetJournal().GetJournalHistory();
|
||||
bool useNewEditor = journalHistory.empty() || journalHistory.front().journalEntryType != JournalEntryType::LegacyObject;
|
||||
bool useNewEditor =
|
||||
journalHistory.empty() || journalHistory.front().journalEntryType != JournalEntryType::LegacyObject;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -635,204 +620,203 @@ void Editor::UploadChanges(string const & oauthToken, ChangesetTags tags,
|
||||
|
||||
switch (fti.m_status)
|
||||
{
|
||||
case FeatureStatus::Untouched:
|
||||
CHECK(false, ("It's impossible."));
|
||||
continue;
|
||||
case FeatureStatus::Obsolete:
|
||||
continue; // Obsolete features will be deleted by OSMers.
|
||||
case FeatureStatus::Created: // fallthrough
|
||||
case FeatureStatus::Modified:
|
||||
case FeatureStatus::Untouched: CHECK(false, ("It's impossible.")); continue;
|
||||
case FeatureStatus::Obsolete: continue; // Obsolete features will be deleted by OSMers.
|
||||
case FeatureStatus::Created: // fallthrough
|
||||
case FeatureStatus::Modified:
|
||||
{
|
||||
std::list<JournalEntry> const & journal = fti.m_object.GetJournal().GetJournal();
|
||||
|
||||
switch (fti.m_object.GetEditingLifecycle())
|
||||
{
|
||||
std::list<JournalEntry> const & journal = fti.m_object.GetJournal().GetJournal();
|
||||
case EditingLifecycle::CREATED:
|
||||
{
|
||||
// Generate XMLFeature for new object
|
||||
JournalEntry const & createEntry = journal.front();
|
||||
ASSERT(createEntry.journalEntryType == JournalEntryType::ObjectCreated,
|
||||
("First item should have type ObjectCreated"));
|
||||
ObjCreateData const & objCreateData = std::get<ObjCreateData>(createEntry.data);
|
||||
XMLFeature feature =
|
||||
editor::TypeToXML(objCreateData.type, objCreateData.geomType, objCreateData.mercator);
|
||||
|
||||
switch (fti.m_object.GetEditingLifecycle())
|
||||
// Check if place already exists
|
||||
bool mergeSameLocation = false;
|
||||
try
|
||||
{
|
||||
case EditingLifecycle::CREATED:
|
||||
XMLFeature osmFeature = changeset.GetMatchingNodeFeatureFromOSM(objCreateData.mercator);
|
||||
if (objCreateData.mercator == osmFeature.GetMercatorCenter())
|
||||
{
|
||||
// Generate XMLFeature for new object
|
||||
JournalEntry const & createEntry = journal.front();
|
||||
ASSERT(createEntry.journalEntryType == JournalEntryType::ObjectCreated,("First item should have type ObjectCreated"));
|
||||
ObjCreateData const & objCreateData = std::get<ObjCreateData>(createEntry.data);
|
||||
XMLFeature feature = editor::TypeToXML(objCreateData.type, objCreateData.geomType, objCreateData.mercator);
|
||||
|
||||
// Check if place already exists
|
||||
bool mergeSameLocation = false;
|
||||
try
|
||||
{
|
||||
XMLFeature osmFeature = changeset.GetMatchingNodeFeatureFromOSM(objCreateData.mercator);
|
||||
if (objCreateData.mercator == osmFeature.GetMercatorCenter()) {
|
||||
changeset.AddChangesetTag("info:merged_same_location", "yes");
|
||||
feature = osmFeature;
|
||||
mergeSameLocation = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
changeset.AddChangesetTag("info:feature_close_by", "yes");
|
||||
}
|
||||
}
|
||||
catch (ChangesetWrapper::OsmObjectWasDeletedException const &) {}
|
||||
catch (ChangesetWrapper::EmptyFeatureException const &) {}
|
||||
|
||||
// Add tags to XMLFeature
|
||||
UpdateXMLFeatureTags(feature, journal);
|
||||
|
||||
// Upload XMLFeature to OSM
|
||||
LOG(LDEBUG, ("CREATE Feature (newEditor)", feature));
|
||||
changeset.AddChangesetTag("info:new_editor", "yes");
|
||||
if (!mergeSameLocation)
|
||||
changeset.Create(feature);
|
||||
else
|
||||
changeset.Modify(feature);
|
||||
break;
|
||||
changeset.AddChangesetTag("info:merged_same_location", "yes");
|
||||
feature = osmFeature;
|
||||
mergeSameLocation = true;
|
||||
}
|
||||
|
||||
case EditingLifecycle::MODIFIED:
|
||||
else
|
||||
{
|
||||
// Load existing OSM object (Throws, see catch below)
|
||||
XMLFeature feature = GetMatchingFeatureFromOSM(changeset, fti.m_object);
|
||||
|
||||
// Update tags of XMLFeature
|
||||
UpdateXMLFeatureTags(feature, journal);
|
||||
|
||||
// Upload XMLFeature to OSM
|
||||
LOG(LDEBUG, ("MODIFIED Feature (newEditor)", feature));
|
||||
changeset.AddChangesetTag("info:new_editor", "yes");
|
||||
changeset.Modify(feature);
|
||||
break;
|
||||
}
|
||||
|
||||
case EditingLifecycle::IN_SYNC:
|
||||
{
|
||||
CHECK(false, ("Object already IN_SYNC should not be here"));
|
||||
continue;
|
||||
changeset.AddChangesetTag("info:feature_close_by", "yes");
|
||||
}
|
||||
}
|
||||
catch (ChangesetWrapper::OsmObjectWasDeletedException const &)
|
||||
{}
|
||||
catch (ChangesetWrapper::EmptyFeatureException const &)
|
||||
{}
|
||||
|
||||
// Add tags to XMLFeature
|
||||
UpdateXMLFeatureTags(feature, journal);
|
||||
|
||||
// Upload XMLFeature to OSM
|
||||
LOG(LDEBUG, ("CREATE Feature (newEditor)", feature));
|
||||
changeset.AddChangesetTag("info:new_editor", "yes");
|
||||
if (!mergeSameLocation)
|
||||
changeset.Create(feature);
|
||||
else
|
||||
changeset.Modify(feature);
|
||||
break;
|
||||
}
|
||||
case FeatureStatus::Deleted:
|
||||
auto const originalObjectPtr = GetOriginalMapObject(fti.m_object.GetID());
|
||||
if (!originalObjectPtr)
|
||||
{
|
||||
LOG(LERROR, ("A feature with id", fti.m_object.GetID(), "cannot be loaded."));
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,[this, fid = fti.m_object.GetID()]() {
|
||||
RemoveFeatureIfExists(fid);
|
||||
});
|
||||
continue;
|
||||
}
|
||||
changeset.Delete(GetMatchingFeatureFromOSM(changeset, *originalObjectPtr));
|
||||
|
||||
case EditingLifecycle::MODIFIED:
|
||||
{
|
||||
// Load existing OSM object (Throws, see catch below)
|
||||
XMLFeature feature = GetMatchingFeatureFromOSM(changeset, fti.m_object);
|
||||
|
||||
// Update tags of XMLFeature
|
||||
UpdateXMLFeatureTags(feature, journal);
|
||||
|
||||
// Upload XMLFeature to OSM
|
||||
LOG(LDEBUG, ("MODIFIED Feature (newEditor)", feature));
|
||||
changeset.AddChangesetTag("info:new_editor", "yes");
|
||||
changeset.Modify(feature);
|
||||
break;
|
||||
}
|
||||
|
||||
case EditingLifecycle::IN_SYNC:
|
||||
{
|
||||
CHECK(false, ("Object already IN_SYNC should not be here"));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FeatureStatus::Deleted:
|
||||
auto const originalObjectPtr = GetOriginalMapObject(fti.m_object.GetID());
|
||||
if (!originalObjectPtr)
|
||||
{
|
||||
LOG(LERROR, ("A feature with id", fti.m_object.GetID(), "cannot be loaded."));
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,
|
||||
[this, fid = fti.m_object.GetID()]() { RemoveFeatureIfExists(fid); });
|
||||
continue;
|
||||
}
|
||||
changeset.Delete(GetMatchingFeatureFromOSM(changeset, *originalObjectPtr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else // Use old editor
|
||||
else // Use old editor
|
||||
{
|
||||
// Todo: Remove old editor after transition period
|
||||
switch (fti.m_status)
|
||||
{
|
||||
case FeatureStatus::Untouched: CHECK(false, ("It's impossible.")); continue;
|
||||
case FeatureStatus::Obsolete: continue; // Obsolete features will be deleted by OSMers.
|
||||
case 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_object, true);
|
||||
if (!fti.m_street.empty())
|
||||
feature.SetTagValue(kAddrStreetTag, fti.m_street);
|
||||
|
||||
ASSERT_EQUAL(feature.GetType(), XMLFeature::Type::Node,
|
||||
("Linear and area features creation is not supported yet."));
|
||||
try
|
||||
{
|
||||
XMLFeature feature = editor::ToXML(fti.m_object, true);
|
||||
if (!fti.m_street.empty())
|
||||
feature.SetTagValue(kAddrStreetTag, fti.m_street);
|
||||
auto const center = fti.m_object.GetMercator();
|
||||
// Throws, see catch below.
|
||||
XMLFeature osmFeature = changeset.GetMatchingNodeFeatureFromOSM(center);
|
||||
|
||||
ASSERT_EQUAL(feature.GetType(), XMLFeature::Type::Node,
|
||||
("Linear and area features creation is not supported yet."));
|
||||
try
|
||||
{
|
||||
auto const center = fti.m_object.GetMercator();
|
||||
// Throws, see catch below.
|
||||
XMLFeature osmFeature = changeset.GetMatchingNodeFeatureFromOSM(center);
|
||||
|
||||
// If we are here, it means that object already exists at the given point.
|
||||
// To avoid nodes duplication, merge and apply changes to it instead of creating a new one.
|
||||
XMLFeature const osmFeatureCopy = osmFeature;
|
||||
osmFeature.ApplyPatch(feature);
|
||||
// Check to avoid uploading duplicates into OSM.
|
||||
if (osmFeature == osmFeatureCopy)
|
||||
{
|
||||
LOG(LWARNING,("Local changes are equal to OSM, feature has not been uploaded.", osmFeatureCopy));
|
||||
// Don't delete this local change right now for user to see it in profile.
|
||||
// It will be automatically deleted by migration code on the next maps update.
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LDEBUG, ("Create case: uploading patched feature", osmFeature));
|
||||
changeset.AddChangesetTag("info:old_editor", "yes");
|
||||
changeset.AddChangesetTag("info:features_merged", "yes");
|
||||
changeset.Modify(osmFeature);
|
||||
}
|
||||
}
|
||||
catch (ChangesetWrapper::OsmObjectWasDeletedException const &)
|
||||
{
|
||||
// Object was never created by anyone else - it's safe to create it.
|
||||
changeset.AddChangesetTag("info:old_editor", "yes");
|
||||
changeset.Create(feature);
|
||||
}
|
||||
catch (ChangesetWrapper::EmptyFeatureException const &)
|
||||
{
|
||||
// There is another node nearby, but it should be safe to create a new one.
|
||||
changeset.AddChangesetTag("info:old_editor", "yes");
|
||||
changeset.Create(feature);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Pass network or other errors to outside exception handler.
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
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.
|
||||
XMLFeature feature = editor::ToXML(fti.m_object, false);
|
||||
if (!fti.m_street.empty())
|
||||
feature.SetTagValue(kAddrStreetTag, fti.m_street);
|
||||
|
||||
auto const originalObjectPtr = GetOriginalMapObject(fti.m_object.GetID());
|
||||
if (!originalObjectPtr)
|
||||
{
|
||||
LOG(LERROR, ("A feature with id", fti.m_object.GetID(), "cannot be loaded."));
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,[this, fid = fti.m_object.GetID()]() {
|
||||
RemoveFeatureIfExists(fid);
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
XMLFeature osmFeature = GetMatchingFeatureFromOSM(changeset, *originalObjectPtr);
|
||||
// If we are here, it means that object already exists at the given point.
|
||||
// To avoid nodes duplication, merge and apply changes to it instead of creating a new one.
|
||||
XMLFeature const osmFeatureCopy = osmFeature;
|
||||
osmFeature.ApplyPatch(feature);
|
||||
// Check to avoid uploading duplicates into OSM.
|
||||
if (osmFeature == osmFeatureCopy)
|
||||
{
|
||||
LOG(LWARNING,("Local changes are equal to OSM, feature has not been uploaded.", osmFeatureCopy));
|
||||
LOG(LWARNING, ("Local changes are equal to OSM, feature has not been uploaded.", osmFeatureCopy));
|
||||
// Don't delete this local change right now for user to see it in profile.
|
||||
// It will be automatically deleted by migration code on the next maps update.
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LDEBUG, ("Uploading patched feature", osmFeature));
|
||||
LOG(LDEBUG, ("Create case: uploading patched feature", osmFeature));
|
||||
changeset.AddChangesetTag("info:old_editor", "yes");
|
||||
changeset.AddChangesetTag("info:features_merged", "yes");
|
||||
changeset.Modify(osmFeature);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FeatureStatus::Deleted:
|
||||
auto const originalObjectPtr = GetOriginalMapObject(fti.m_object.GetID());
|
||||
if (!originalObjectPtr)
|
||||
{
|
||||
LOG(LERROR, ("A feature with id", fti.m_object.GetID(), "cannot be loaded."));
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,[this, fid = fti.m_object.GetID()]() {
|
||||
RemoveFeatureIfExists(fid);
|
||||
});
|
||||
continue;
|
||||
}
|
||||
catch (ChangesetWrapper::OsmObjectWasDeletedException const &)
|
||||
{
|
||||
// Object was never created by anyone else - it's safe to create it.
|
||||
changeset.AddChangesetTag("info:old_editor", "yes");
|
||||
changeset.Delete(GetMatchingFeatureFromOSM(changeset, *originalObjectPtr));
|
||||
break;
|
||||
changeset.Create(feature);
|
||||
}
|
||||
catch (ChangesetWrapper::EmptyFeatureException const &)
|
||||
{
|
||||
// There is another node nearby, but it should be safe to create a new one.
|
||||
changeset.AddChangesetTag("info:old_editor", "yes");
|
||||
changeset.Create(feature);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Pass network or other errors to outside exception handler.
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
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.
|
||||
XMLFeature feature = editor::ToXML(fti.m_object, false);
|
||||
if (!fti.m_street.empty())
|
||||
feature.SetTagValue(kAddrStreetTag, fti.m_street);
|
||||
|
||||
auto const originalObjectPtr = GetOriginalMapObject(fti.m_object.GetID());
|
||||
if (!originalObjectPtr)
|
||||
{
|
||||
LOG(LERROR, ("A feature with id", fti.m_object.GetID(), "cannot be loaded."));
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,
|
||||
[this, fid = fti.m_object.GetID()]() { RemoveFeatureIfExists(fid); });
|
||||
continue;
|
||||
}
|
||||
|
||||
XMLFeature osmFeature = GetMatchingFeatureFromOSM(changeset, *originalObjectPtr);
|
||||
XMLFeature const osmFeatureCopy = osmFeature;
|
||||
osmFeature.ApplyPatch(feature);
|
||||
// Check to avoid uploading duplicates into OSM.
|
||||
if (osmFeature == osmFeatureCopy)
|
||||
{
|
||||
LOG(LWARNING, ("Local changes are equal to OSM, feature has not been uploaded.", osmFeatureCopy));
|
||||
// Don't delete this local change right now for user to see it in profile.
|
||||
// It will be automatically deleted by migration code on the next maps update.
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LDEBUG, ("Uploading patched feature", osmFeature));
|
||||
changeset.AddChangesetTag("info:old_editor", "yes");
|
||||
changeset.Modify(osmFeature);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FeatureStatus::Deleted:
|
||||
auto const originalObjectPtr = GetOriginalMapObject(fti.m_object.GetID());
|
||||
if (!originalObjectPtr)
|
||||
{
|
||||
LOG(LERROR, ("A feature with id", fti.m_object.GetID(), "cannot be loaded."));
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,
|
||||
[this, fid = fti.m_object.GetID()]() { RemoveFeatureIfExists(fid); });
|
||||
continue;
|
||||
}
|
||||
changeset.AddChangesetTag("info:old_editor", "yes");
|
||||
changeset.Delete(GetMatchingFeatureFromOSM(changeset, *originalObjectPtr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
uploadInfo.m_uploadStatus = kUploaded;
|
||||
@@ -866,11 +850,11 @@ void Editor::UploadChanges(string const & oauthToken, ChangesetTags tags,
|
||||
// TODO(AlexZ): Use timestamp from the server.
|
||||
uploadInfo.m_uploadAttemptTimestamp = time(nullptr);
|
||||
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,
|
||||
[this, id = fti.m_object.GetID(), uploadInfo]() {
|
||||
// Call Save every time we modify each feature's information.
|
||||
SaveUploadedInformation(id, uploadInfo);
|
||||
});
|
||||
GetPlatform().RunTask(Platform::Thread::Gui, [this, id = fti.m_object.GetID(), uploadInfo]()
|
||||
{
|
||||
// Call Save every time we modify each feature's information.
|
||||
SaveUploadedInformation(id, uploadInfo);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -891,11 +875,9 @@ void Editor::UploadChanges(string const & oauthToken, ChangesetTags tags,
|
||||
if (!m_isUploadingNow)
|
||||
{
|
||||
m_isUploadingNow = true;
|
||||
GetPlatform().RunTask(Platform::Thread::Network, [upload = std::move(upload), oauthToken,
|
||||
tags = std::move(tags), callback = std::move(callback)]()
|
||||
{
|
||||
upload(std::move(oauthToken), std::move(tags), std::move(callback));
|
||||
});
|
||||
GetPlatform().RunTask(Platform::Thread::Network, [upload = std::move(upload), oauthToken, tags = std::move(tags),
|
||||
callback = std::move(callback)]()
|
||||
{ upload(std::move(oauthToken), std::move(tags), std::move(callback)); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -934,7 +916,8 @@ bool Editor::FillFeatureInfo(FeatureStatus status, XMLFeature const & xml, Featu
|
||||
|
||||
// Do not load Legacy Objects form Journal
|
||||
auto const & journalHistory = journal.GetJournalHistory();
|
||||
bool loadFromJournal = journalHistory.empty() || journalHistory.front().journalEntryType != JournalEntryType::LegacyObject;
|
||||
bool loadFromJournal =
|
||||
journalHistory.empty() || journalHistory.front().journalEntryType != JournalEntryType::LegacyObject;
|
||||
|
||||
LOG(LDEBUG, ("loadFromJournal: ", loadFromJournal));
|
||||
|
||||
@@ -976,8 +959,7 @@ bool Editor::FillFeatureInfo(FeatureStatus status, XMLFeature const & xml, Featu
|
||||
return true;
|
||||
}
|
||||
|
||||
Editor::FeatureTypeInfo const * Editor::GetFeatureTypeInfo(FeaturesContainer const & features,
|
||||
MwmId const & mwmId,
|
||||
Editor::FeatureTypeInfo const * Editor::GetFeatureTypeInfo(FeaturesContainer const & features, MwmId const & mwmId,
|
||||
uint32_t index)
|
||||
{
|
||||
auto const matchedMwm = features.find(mwmId);
|
||||
@@ -1063,13 +1045,11 @@ Editor::Stats Editor::GetStats() const
|
||||
for (auto & index : id.second)
|
||||
{
|
||||
auto const & fti = index.second;
|
||||
stats.m_edits.emplace_back(FeatureID(id.first, index.first),
|
||||
fti.m_uploadStatus + " " + fti.m_uploadError);
|
||||
stats.m_edits.emplace_back(FeatureID(id.first, index.first), fti.m_uploadStatus + " " + fti.m_uploadError);
|
||||
LOG(LDEBUG, (fti.m_uploadAttemptTimestamp == base::INVALID_TIME_STAMP
|
||||
? "NOT_UPLOADED_YET"
|
||||
: base::TimestampToString(fti.m_uploadAttemptTimestamp),
|
||||
fti.m_uploadStatus, fti.m_uploadError, fti.m_object.GetGeomType(),
|
||||
fti.m_object.GetMercator()));
|
||||
fti.m_uploadStatus, fti.m_uploadError, fti.m_object.GetGeomType(), fti.m_object.GetMercator()));
|
||||
if (fti.m_uploadStatus == kUploaded)
|
||||
{
|
||||
++stats.m_uploadedCount;
|
||||
@@ -1086,8 +1066,7 @@ NewFeatureCategories Editor::GetNewFeatureCategories() const
|
||||
return NewFeatureCategories(*(m_config.Get()));
|
||||
}
|
||||
|
||||
FeatureID Editor::GenerateNewFeatureId(FeaturesContainer const & features,
|
||||
MwmId const & id) const
|
||||
FeatureID Editor::GenerateNewFeatureId(FeaturesContainer const & features, MwmId const & id) const
|
||||
{
|
||||
CHECK_THREAD_CHECKER(MainThreadChecker, (""));
|
||||
|
||||
@@ -1098,10 +1077,8 @@ FeatureID Editor::GenerateNewFeatureId(FeaturesContainer const & features,
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
CHECK(feature::FakeFeatureIds::IsEditorCreatedFeature(featureIndex), ());
|
||||
return {id, featureIndex};
|
||||
@@ -1110,8 +1087,7 @@ FeatureID Editor::GenerateNewFeatureId(FeaturesContainer const & features,
|
||||
bool Editor::CreatePoint(uint32_t type, m2::PointD const & mercator, MwmId const & id,
|
||||
EditableMapObject & outFeature) const
|
||||
{
|
||||
ASSERT(id.IsAlive(),
|
||||
("Please check that feature is created in valid MWM file before calling this method."));
|
||||
ASSERT(id.IsAlive(), ("Please check that feature is created in valid MWM file before calling this method."));
|
||||
if (!id.GetInfo()->m_bordersRect.IsPointInside(mercator))
|
||||
{
|
||||
LOG(LERROR, ("Attempt to create a feature outside of the MWM's bounding box."));
|
||||
@@ -1128,9 +1104,8 @@ bool Editor::CreatePoint(uint32_t type, m2::PointD const & mercator, MwmId const
|
||||
return true;
|
||||
}
|
||||
|
||||
void Editor::CreateNote(ms::LatLon const & latLon, FeatureID const & fid,
|
||||
feature::TypesHolder const & holder, std::string_view defaultName,
|
||||
NoteProblemType type, std::string_view note)
|
||||
void Editor::CreateNote(ms::LatLon const & latLon, FeatureID const & fid, feature::TypesHolder const & holder,
|
||||
std::string_view defaultName, NoteProblemType type, std::string_view note)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(MainThreadChecker, (""));
|
||||
|
||||
@@ -1148,10 +1123,8 @@ void Editor::CreateNote(ms::LatLon const & latLon, FeatureID const & fid,
|
||||
"that the POI was visible on the map (see snapshot date below), but was not found "
|
||||
"on the ground.\n";
|
||||
auto const features = m_features.Get();
|
||||
auto const isCreated =
|
||||
GetFeatureStatusImpl(*features, fid.m_mwmId, fid.m_index) == FeatureStatus::Created;
|
||||
auto const createdAndUploaded =
|
||||
(isCreated && IsFeatureUploadedImpl(*features, fid.m_mwmId, fid.m_index));
|
||||
auto const isCreated = GetFeatureStatusImpl(*features, fid.m_mwmId, fid.m_index) == FeatureStatus::Created;
|
||||
auto const createdAndUploaded = (isCreated && IsFeatureUploadedImpl(*features, fid.m_mwmId, fid.m_index));
|
||||
CHECK(!isCreated || createdAndUploaded, ());
|
||||
|
||||
if (createdAndUploaded)
|
||||
@@ -1190,8 +1163,7 @@ void Editor::CreateStandaloneNote(ms::LatLon const & latLon, std::string const &
|
||||
m_notes->CreateNote(latLon, noteText + "\n");
|
||||
}
|
||||
|
||||
void Editor::MarkFeatureWithStatus(FeaturesContainer & editableFeatures, FeatureID const & fid,
|
||||
FeatureStatus status)
|
||||
void Editor::MarkFeatureWithStatus(FeaturesContainer & editableFeatures, FeatureID const & fid, FeatureStatus status)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(MainThreadChecker, (""));
|
||||
|
||||
@@ -1250,27 +1222,24 @@ void Editor::ForEachFeatureAtPoint(FeatureTypeFn && fn, m2::PointD const & point
|
||||
m_delegate->ForEachFeatureAtPoint(std::move(fn), point);
|
||||
}
|
||||
|
||||
FeatureID Editor::GetFeatureIdByXmlFeature(FeaturesContainer const & features,
|
||||
XMLFeature const & xml, MwmId const & mwmId,
|
||||
FeatureStatus status, bool needMigrate) const
|
||||
FeatureID Editor::GetFeatureIdByXmlFeature(FeaturesContainer const & features, XMLFeature const & xml,
|
||||
MwmId const & mwmId, FeatureStatus status, bool needMigrate) const
|
||||
{
|
||||
ForEachFeaturesNearByFn forEach = [this](FeatureTypeFn && fn, m2::PointD const & point) {
|
||||
return ForEachFeatureAtPoint(std::move(fn), point);
|
||||
};
|
||||
ForEachFeaturesNearByFn forEach = [this](FeatureTypeFn && fn, m2::PointD const & point)
|
||||
{ return ForEachFeatureAtPoint(std::move(fn), point); };
|
||||
|
||||
// TODO(mgsergio): Deleted features are not properly handled yet.
|
||||
if (needMigrate)
|
||||
{
|
||||
return editor::MigrateFeatureIndex(forEach, xml, status, [this, &mwmId, &features] {
|
||||
return GenerateNewFeatureId(features, mwmId);
|
||||
});
|
||||
return editor::MigrateFeatureIndex(forEach, xml, status,
|
||||
[this, &mwmId, &features] { return GenerateNewFeatureId(features, mwmId); });
|
||||
}
|
||||
|
||||
return {mwmId, xml.GetMWMFeatureIndex()};
|
||||
}
|
||||
|
||||
void Editor::LoadMwmEdits(FeaturesContainer & loadedFeatures, xml_node const & mwm,
|
||||
MwmId const & mwmId, bool needMigrate)
|
||||
void Editor::LoadMwmEdits(FeaturesContainer & loadedFeatures, xml_node const & mwm, MwmId const & mwmId,
|
||||
bool needMigrate)
|
||||
{
|
||||
LogHelper logHelper(mwmId);
|
||||
|
||||
@@ -1282,8 +1251,7 @@ void Editor::LoadMwmEdits(FeaturesContainer & loadedFeatures, xml_node const & m
|
||||
{
|
||||
XMLFeature const xml(nodeOrWay.node());
|
||||
|
||||
auto const fid =
|
||||
GetFeatureIdByXmlFeature(loadedFeatures, xml, mwmId, section.m_status, needMigrate);
|
||||
auto const fid = GetFeatureIdByXmlFeature(loadedFeatures, xml, mwmId, section.m_status, needMigrate);
|
||||
|
||||
// Remove obsolete changes during migration.
|
||||
if (needMigrate && IsObsolete(xml, fid))
|
||||
@@ -1327,16 +1295,13 @@ bool Editor::HaveMapEditsToUpload(FeaturesContainer const & features)
|
||||
continue;
|
||||
|
||||
for (auto const & index : id.second)
|
||||
{
|
||||
if (NeedsUpload(index.second.m_uploadStatus))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FeatureStatus Editor::GetFeatureStatusImpl(FeaturesContainer const & features,
|
||||
MwmId const & mwmId, uint32_t index)
|
||||
FeatureStatus Editor::GetFeatureStatusImpl(FeaturesContainer const & features, MwmId const & mwmId, uint32_t index)
|
||||
{
|
||||
// Most popular case optimization.
|
||||
if (features.empty())
|
||||
@@ -1357,21 +1322,18 @@ bool Editor::IsFeatureUploadedImpl(FeaturesContainer const & features, MwmId con
|
||||
|
||||
void Editor::UpdateXMLFeatureTags(editor::XMLFeature & feature, std::list<JournalEntry> const & journal)
|
||||
{
|
||||
for (JournalEntry const & entry: journal)
|
||||
for (JournalEntry const & entry : journal)
|
||||
{
|
||||
switch (entry.journalEntryType)
|
||||
{
|
||||
case JournalEntryType::TagModification:
|
||||
{
|
||||
TagModData const & tagModData = std::get<TagModData>(entry.data);
|
||||
feature.UpdateOSMTag(tagModData.key, tagModData.new_value);
|
||||
break;
|
||||
}
|
||||
case JournalEntryType::ObjectCreated:
|
||||
break;
|
||||
case JournalEntryType::LegacyObject:
|
||||
ASSERT_FAIL(("Legacy Objects can not be edited with the new editor"));
|
||||
break;
|
||||
case JournalEntryType::TagModification:
|
||||
{
|
||||
TagModData const & tagModData = std::get<TagModData>(entry.data);
|
||||
feature.UpdateOSMTag(tagModData.key, tagModData.new_value);
|
||||
break;
|
||||
}
|
||||
case JournalEntryType::ObjectCreated: break;
|
||||
case JournalEntryType::LegacyObject: ASSERT_FAIL(("Legacy Objects can not be edited with the new editor")); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1380,11 +1342,11 @@ string DebugPrint(Editor::SaveResult saveResult)
|
||||
{
|
||||
switch (saveResult)
|
||||
{
|
||||
case Editor::SaveResult::NothingWasChanged: return "NothingWasChanged";
|
||||
case Editor::SaveResult::SavedSuccessfully: return "SavedSuccessfully";
|
||||
case Editor::SaveResult::NoFreeSpaceError: return "NoFreeSpaceError";
|
||||
case Editor::SaveResult::NoUnderlyingMapError: return "NoUnderlyingMapError";
|
||||
case Editor::SaveResult::SavingError: return "SavingError";
|
||||
case Editor::SaveResult::NothingWasChanged: return "NothingWasChanged";
|
||||
case Editor::SaveResult::SavedSuccessfully: return "SavedSuccessfully";
|
||||
case Editor::SaveResult::NoFreeSpaceError: return "NoFreeSpaceError";
|
||||
case Editor::SaveResult::NoUnderlyingMapError: return "NoUnderlyingMapError";
|
||||
case Editor::SaveResult::SavingError: return "SavingError";
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user