[editor] Remove unused code from the old OSM editor

Signed-off-by: map-per <map-per@gmx.de>
This commit is contained in:
map-per
2025-12-07 11:16:16 +01:00
committed by map-per
parent d473361e54
commit e7cc602904
8 changed files with 251 additions and 598 deletions

View File

@@ -610,221 +610,101 @@ void Editor::UploadChanges(string const & oauthToken, ChangesetTags tags, Finish
LOG(LDEBUG, ("Content of editJournal:\n", fti.m_object.GetJournal().JournalToString()));
// 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;
try
{
if (useNewEditor)
switch (fti.m_status)
{
LOG(LDEBUG, ("New Editor used\n"));
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:
{
std::list<JournalEntry> const & journal = fti.m_object.GetJournal().GetJournal();
switch (fti.m_object.GetEditingLifecycle())
{
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);
// Check if place already exists
bool mergeSameLocation = false;
try
{
XMLFeature osmFeature = changeset.GetMatchingNodeFeatureFromOSM(objCreateData.mercator);
// precision of OSM coordinates (WGS 84), ~= 1 cm
constexpr double tolerance = 0.0000001;
if (AlmostEqualAbs(feature.GetCenter(), osmFeature.GetCenter(), tolerance))
{
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, changeset);
// 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 EditingLifecycle::MODIFIED:
{
// Load existing OSM object (Throws, see catch below)
XMLFeature feature = GetMatchingFeatureFromOSM(changeset, fti.m_object);
// Update tags of XMLFeature
UpdateXMLFeatureTags(feature, journal, changeset);
// 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
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:
{
// 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:
{
XMLFeature feature = editor::ToXML(fti.m_object, true);
if (!fti.m_street.empty())
feature.SetTagValue(kAddrStreetTag, fti.m_street);
std::list<JournalEntry> const & journal = fti.m_object.GetJournal().GetJournal();
ASSERT_EQUAL(feature.GetType(), XMLFeature::Type::Node,
("Linear and area features creation is not supported yet."));
switch (fti.m_object.GetEditingLifecycle())
{
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);
// Check if place already exists
bool mergeSameLocation = false;
try
{
auto const center = fti.m_object.GetMercator();
// Throws, see catch below.
XMLFeature osmFeature = changeset.GetMatchingNodeFeatureFromOSM(center);
XMLFeature osmFeature = changeset.GetMatchingNodeFeatureFromOSM(objCreateData.mercator);
// 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)
// precision of OSM coordinates (WGS 84), ~= 1 cm
constexpr double tolerance = 0.0000001;
if (AlmostEqualAbs(feature.GetCenter(), osmFeature.GetCenter(), tolerance))
{
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.
changeset.AddChangesetTag("info:merged_same_location", "yes");
feature = osmFeature;
mergeSameLocation = true;
}
else
{
LOG(LDEBUG, ("Create case: uploading patched feature", osmFeature));
changeset.AddChangesetTag("info:old_editor", "yes");
changeset.AddChangesetTag("info:features_merged", "yes");
changeset.Modify(osmFeature);
changeset.AddChangesetTag("info:feature_close_by", "yes");
}
}
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");
{}
// Add tags to XMLFeature
UpdateXMLFeatureTags(feature, journal, changeset);
// Upload XMLFeature to OSM
LOG(LDEBUG, ("CREATE Feature (newEditor)", feature));
changeset.AddChangesetTag("info:new_editor", "yes");
if (!mergeSameLocation)
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));
changeset.Modify(feature);
break;
}
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, changeset);
// 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;
}
uploadInfo.m_uploadStatus = kUploaded;
uploadInfo.m_uploadError.clear();
@@ -907,23 +787,7 @@ void Editor::SaveUploadedInformation(FeatureID const & fid, UploadInfo const & u
bool Editor::FillFeatureInfo(FeatureStatus status, XMLFeature const & xml, FeatureID const & fid,
FeatureTypeInfo & fti) const
{
EditJournal journal = xml.GetEditJournal();
// Do not load Legacy Objects form Journal
auto const & journalHistory = journal.GetJournalHistory();
bool loadFromJournal =
journalHistory.empty() || journalHistory.front().journalEntryType != JournalEntryType::LegacyObject;
LOG(LDEBUG, ("loadFromJournal: ", loadFromJournal));
if (status == FeatureStatus::Created)
{
if (loadFromJournal)
fti.m_object.ApplyEditsFromJournal(journal);
else
editor::FromXML(xml, fti.m_object);
}
else
if (status != FeatureStatus::Created)
{
auto const originalObjectPtr = GetOriginalMapObject(fid);
if (!originalObjectPtr)
@@ -933,13 +797,11 @@ bool Editor::FillFeatureInfo(FeatureStatus status, XMLFeature const & xml, Featu
}
fti.m_object = *originalObjectPtr;
if (loadFromJournal)
fti.m_object.ApplyEditsFromJournal(journal);
else
editor::ApplyPatch(xml, fti.m_object);
}
EditJournal journal = xml.GetEditJournal();
fti.m_object.ApplyEditsFromJournal(journal);
fti.m_object.SetJournal(std::move(journal));
fti.m_object.SetID(fid);
fti.m_street = xml.GetTagValue(kAddrStreetTag);