diff --git a/generator/transit_generator.cpp b/generator/transit_generator.cpp index 4fab82ce70..373e76fde7 100644 --- a/generator/transit_generator.cpp +++ b/generator/transit_generator.cpp @@ -1,7 +1,5 @@ #include "generator/transit_generator.hpp" -#include "generator/borders_generator.hpp" -#include "generator/borders_loader.hpp" #include "generator/utils.hpp" #include "traffic/traffic_cache.hpp" @@ -50,16 +48,6 @@ using namespace std; namespace { -template -void DeserializeItemFromJson(my::Json const & root, string const & key, - OsmIdToFeatureIdsMap const & osmIdToFeatureIdsMap, - vector & items) -{ - items.clear(); - DeserializerFromJson deserializer(root.get(), osmIdToFeatureIdsMap); - deserializer(items, key.c_str()); -} - template bool IsValid(vector const & items) { @@ -72,24 +60,6 @@ struct ClearVisitor void operator()(Cont & c, char const * /* name */ = nullptr) const { c.clear(); } }; -struct DeserializeFromJsonVisitor -{ - DeserializeFromJsonVisitor(my::Json const & root, OsmIdToFeatureIdsMap const & mapping) - : m_root(root), m_mapping(mapping) - { - } - - template - void operator()(Cont & c, char const * name = nullptr) const - { - DeserializeItemFromJson(m_root, name, m_mapping, c); - } - -private: - my::Json const & m_root; - OsmIdToFeatureIdsMap const & m_mapping; -}; - struct SortVisitor { template @@ -180,13 +150,6 @@ string GetMwmPath(string const & mwmDir, string const & countryId) return my::JoinFoldersToPath(mwmDir, countryId + DATA_FILE_EXTENSION); } -void LoadBorders(string const & dir, string const & countryId, vector & borders) -{ - string const polyFile = my::JoinPath(dir, BORDERS_DIR, countryId + BORDERS_EXTENSION); - borders.clear(); - osm::LoadBorders(polyFile, borders); -} - template void Append(vector const & src, vector & dst) { @@ -251,8 +214,8 @@ void DeserializerFromJson::operator()(StopIdRanges & rs, char const * name) // GraphData -------------------------------------------------------------------------------------- void GraphData::DeserializeFromJson(my::Json const & root, OsmIdToFeatureIdsMap const & mapping) { - DeserializeFromJsonVisitor const v(root, mapping); - Visit(v); + DeserializerFromJson deserializer(root.get(), mapping); + Visit(deserializer); } void GraphData::SerializeToMwm(string const & mwmPath) const @@ -403,12 +366,6 @@ void GraphData::CalculateBestPedestrianSegments(string const & mwmPath, string c } } -void GraphData::ClipGraphByMwm(std::vector const & mwmBorders) -{ - // @todo(bykoianko) Rules for graph clipping should be implemented here. - -} - bool GraphData::IsUnique() const { IsUniqueVisitor v; @@ -461,33 +418,22 @@ void ProcessGraph(string const & mwmPath, string const & countryId, void BuildTransit(string const & mwmDir, string const & countryId, string const & osmIdToFeatureIdsPath, string const & transitDir) { + // @todo(bykoianko) It's assumed that the method builds transit section based on clipped json. + // Json clipping should be implemented at the feature generation step. + LOG(LERROR, ("This method is under construction and should not be used for building production mwm " "sections.")); NOTIMPLEMENTED(); - Platform::FilesList graphFiles; - Platform::GetFilesByExt(transitDir, TRANSIT_FILE_EXTENSION, graphFiles); - + string const graphFullPath = my::JoinFoldersToPath(transitDir, countryId + TRANSIT_FILE_EXTENSION); string const mwmPath = GetMwmPath(mwmDir, countryId); OsmIdToFeatureIdsMap mapping; FillOsmIdToFeatureIdsMap(osmIdToFeatureIdsPath, mapping); - vector mwmBorders; - LoadBorders(mwmDir, countryId, mwmBorders); - GraphData jointData; - - for (auto const & filePath : graphFiles) - { - GraphData data; - DeserializeFromJson(mapping, filePath, data); - ProcessGraph(mwmPath, countryId, mapping, data); - data.ClipGraphByMwm(mwmBorders); - jointData.Append(data); - } - - jointData.Sort(); - CHECK(jointData.IsValid(), (mwmPath, countryId)); - jointData.SerializeToMwm(mwmPath); + GraphData data; + DeserializeFromJson(mapping, graphFullPath, data); + ProcessGraph(mwmPath, countryId, mapping, data); + data.SerializeToMwm(mwmPath); } } // namespace transit } // namespace routing diff --git a/generator/transit_generator.hpp b/generator/transit_generator.hpp index ecafdf1518..7d0de361c4 100644 --- a/generator/transit_generator.hpp +++ b/generator/transit_generator.hpp @@ -5,7 +5,6 @@ #include "routing_common/transit_types.hpp" #include "geometry/point2d.hpp" -#include "geometry/region2d.hpp" #include "base/macros.hpp" @@ -105,7 +104,7 @@ private: OsmIdToFeatureIdsMap const & m_osmIdToFeatureIds; }; -/// \brief the data contains all the information to make TRANSIT_FILE_TAG section. +/// \brief The class contains all the information to make TRANSIT_FILE_TAG section. class GraphData { public: @@ -124,9 +123,6 @@ public: /// \brief Calculates best pedestrian segment for every gate in |m_gates|. /// \note All gates in |m_gates| should have a valid |m_point| field before the call. void CalculateBestPedestrianSegments(std::string const & mwmPath, std::string const & countryId); - /// \brief Removes some items from all the class fields if they outside |mwmBorders|. - /// @todo(bykoinko) Certain rules which is used to clip the transit graph should be described here. - void ClipGraphByMwm(std::vector const & mwmBorders); std::vector const & GetStops() const { return m_stops; } std::vector const & GetGates() const { return m_gates; } @@ -154,8 +150,6 @@ private: std::vector m_networks; }; -// @todo(bykoianko) Method below should be covered with tests. - /// \brief Fills |data| according to a transit graph (|transitJsonPath|). /// \note Some of fields of |data| contains feature ids of a certain mwm. These fields are filled /// iff the mapping (|osmIdToFeatureIdsPath|) contains them. Otherwise the fields have default value. @@ -167,12 +161,13 @@ void DeserializeFromJson(OsmIdToFeatureIdsMap const & mapping, std::string const void ProcessGraph(std::string const & mwmPath, std::string const & countryId, OsmIdToFeatureIdsMap const & osmIdToFeatureIdsMap, GraphData & data); -/// \brief Builds the transit section in the mwm. +/// \brief Builds the transit section in the mwm based on transit graph in json which represents +/// trasit graph clipped by the mwm borders. /// \param mwmDir relative or full path to a directory where mwm is located. /// \param countryId is an mwm name without extension of the processed mwm. /// \param osmIdToFeatureIdsPath is a path to a file with osm id to feature ids mapping. /// \param transitDir a path with slash at the end to directory with json files with transit graphs. -/// It's assumed that the files has extension TRANSIT_FILE_EXTENSION. +/// It's assumed that the files have name the same with country ids and extension TRANSIT_FILE_EXTENSION. /// \note An mwm pointed by |mwmPath| should contain: /// * feature geometry /// * index graph (ROUTING_FILE_TAG)