mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-23 06:33:42 +00:00
[editor] Mark businesse as disused/vacant
Signed-off-by: map-per <map-per@gmx.de>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "editor/xml_feature.hpp"
|
||||
#include "editor/keys_to_remove.hpp"
|
||||
|
||||
#include "indexer/classificator.hpp"
|
||||
#include "indexer/editable_map_object.hpp"
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "base/timer.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -502,6 +504,29 @@ osm::EditJournal XMLFeature::GetEditJournal() const
|
||||
entry.data = legacyObjData;
|
||||
break;
|
||||
}
|
||||
case osm::JournalEntryType::BusinessReplacement:
|
||||
{
|
||||
osm::BusinessReplacementData businessReplacementData;
|
||||
|
||||
// Old Feature Type
|
||||
std::string old_strType = getAttribute(xmlData, "old_type");
|
||||
if (old_strType.empty())
|
||||
MYTHROW(editor::InvalidJournalEntry, ("Old Feature type is empty"));
|
||||
businessReplacementData.old_type = classif().GetTypeByReadableObjectName(old_strType);
|
||||
if (businessReplacementData.old_type == IndexAndTypeMapping::INVALID_TYPE)
|
||||
MYTHROW(editor::InvalidJournalEntry, ("Invalid old Feature Type:", old_strType));
|
||||
|
||||
// New Feature Type
|
||||
std::string new_strType = getAttribute(xmlData, "new_type");
|
||||
if (new_strType.empty())
|
||||
MYTHROW(editor::InvalidJournalEntry, ("New Feature type is empty"));
|
||||
businessReplacementData.new_type = classif().GetTypeByReadableObjectName(new_strType);
|
||||
if (businessReplacementData.new_type == IndexAndTypeMapping::INVALID_TYPE)
|
||||
MYTHROW(editor::InvalidJournalEntry, ("Invalid new Feature Type:", new_strType));
|
||||
|
||||
entry.data = businessReplacementData;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isHistory)
|
||||
journal.AddJournalHistoryEntry(entry);
|
||||
@@ -572,6 +597,13 @@ void XMLFeature::SetEditJournal(osm::EditJournal const & journal)
|
||||
xmlData.append_attribute("version") = legacyObjData.version.data();
|
||||
break;
|
||||
}
|
||||
case osm::JournalEntryType::BusinessReplacement:
|
||||
{
|
||||
osm::BusinessReplacementData const & businessReplacementData = std::get<osm::BusinessReplacementData>(entry.data);
|
||||
xmlData.append_attribute("old_type") = classif().GetReadableObjectName(businessReplacementData.old_type).data();
|
||||
xmlData.append_attribute("new_type") = classif().GetReadableObjectName(businessReplacementData.new_type).data();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -675,6 +707,49 @@ void XMLFeature::UpdateOSMTag(std::string_view key, std::string_view value)
|
||||
}
|
||||
}
|
||||
|
||||
void XMLFeature::OSMBusinessReplacement(uint32_t old_type, uint32_t new_type)
|
||||
{
|
||||
std::string name = GetTagValue("name");
|
||||
|
||||
// Remove OSM tags using the list from keys_to_remove.hpp
|
||||
std::string regexPattern;
|
||||
|
||||
for (auto const & key : kKeysToRemove)
|
||||
{
|
||||
if (!regexPattern.empty())
|
||||
regexPattern.append("|");
|
||||
regexPattern.append(key);
|
||||
}
|
||||
|
||||
std::regex regex(regexPattern);
|
||||
|
||||
ForEachTag([& regex, this](std::string_view key, std::string_view /*value*/)
|
||||
{
|
||||
if (std::regex_search(key.begin(), key.end(), regex))
|
||||
RemoveTag(key);
|
||||
});
|
||||
|
||||
if (classif().GetReadableObjectName(new_type) == "disusedbusiness")
|
||||
{
|
||||
// Mark as 'disused'
|
||||
string const strOldType = classif().GetReadableObjectName(old_type);
|
||||
strings::SimpleTokenizer iter(strOldType, "-");
|
||||
string_view const key = *iter;
|
||||
if (++iter)
|
||||
SetTagValue("disused:" + std::string(key), *iter);
|
||||
else
|
||||
SetTagValue("disused:" + std::string(key), "yes");
|
||||
|
||||
SetTagValue("old_name", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add new category tag
|
||||
ASSERT_FAIL("Only marking places as 'disused' is implemented yet. "
|
||||
"Wrong new_type: " + classif().GetReadableObjectName(new_type));
|
||||
}
|
||||
}
|
||||
|
||||
string XMLFeature::GetAttribute(string const & key) const
|
||||
{
|
||||
return GetRootNode().attribute(key.data()).value();
|
||||
|
||||
Reference in New Issue
Block a user