From a2a53df74d48eb30bab7ff657e6af52bf7c9b1d0 Mon Sep 17 00:00:00 2001 From: vng Date: Sat, 4 Jun 2011 21:15:31 +0300 Subject: [PATCH] Draw road's number. --- indexer/feature.hpp | 2 ++ map/draw_info.hpp | 46 +++++++++++++++++++++++++++--------------- map/draw_processor.cpp | 7 ++++--- map/drawer_yg.cpp | 37 ++++++++++++++++++++++++++++----- map/drawer_yg.hpp | 6 ++++-- map/framework.cpp | 1 + 6 files changed, 73 insertions(+), 26 deletions(-) diff --git a/indexer/feature.hpp b/indexer/feature.hpp index febdec9164..13b10174e4 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -379,6 +379,8 @@ public: uint32_t GetPopulation() const; double GetPopulationDrawRank() const; + string GetRoadNumber() const { return m_Params.ref; } + /// @name Statistic functions. //@{ void ParseBeforeStatistic() const diff --git a/map/draw_info.hpp b/map/draw_info.hpp index 915029935d..2d97149bd0 100644 --- a/map/draw_info.hpp +++ b/map/draw_info.hpp @@ -11,19 +11,19 @@ namespace di { class PathInfo { - mutable double m_length; + double m_fullL; double m_offset; public: vector m_path; // -1.0 means "not" initialized - PathInfo(double offset = -1.0) : m_length(-1.0), m_offset(offset) {} + PathInfo(double offset = -1.0) : m_fullL(-1.0), m_offset(offset) {} void swap(PathInfo & r) { m_path.swap(r.m_path); - std::swap(m_length, r.m_length); + std::swap(m_fullL, r.m_fullL); std::swap(m_offset, r.m_offset); } @@ -34,20 +34,11 @@ namespace di size_t size() const { return m_path.size(); } - void SetLength(double len) { m_length = len; } - - double GetLength() const + void SetFullLength(double len) { m_fullL = len; } + double GetFullLength() const { - // m_length not initialized - calculate it - //if (m_length < 0.0) - //{ - // m_length = 0.0; - // for (size_t i = 1; i < m_path.size(); ++i) - // m_length += m_path[i-1].Length(m_path[i]); - //} - - ASSERT ( m_length > 0.0, (m_length) ); - return m_length; + ASSERT ( m_fullL > 0.0, (m_fullL) ); + return m_fullL; } double GetOffset() const @@ -56,6 +47,29 @@ namespace di return m_offset; } + bool GetSmPoint(double part, m2::PointD & pt) const + { + double sum = -GetFullLength() * part + m_offset; + if (sum > 0.0) return false; + + for (size_t i = 1; i < m_path.size(); ++i) + { + double const l = m_path[i-1].Length(m_path[i]); + sum += l; + if (sum >= 0.0) + { + double const factor = (l - sum) / l; + ASSERT_GREATER_OR_EQUAL ( factor, 0.0, () ); + + pt.x = factor * (m_path[i].x - m_path[i-1].x) + m_path[i-1].x; + pt.y = factor * (m_path[i].y - m_path[i-1].y) + m_path[i-1].y; + return true; + } + } + + return false; + } + m2::RectD GetLimitRect() const { m2::RectD rect; diff --git a/map/draw_processor.cpp b/map/draw_processor.cpp index ef3d109b4c..f731e37225 100644 --- a/map/draw_processor.cpp +++ b/map/draw_processor.cpp @@ -85,7 +85,7 @@ void path_points::best_filtration(m2::PointD const & pt) m2::PointD prev = m_prev; m2::PointD curr = pt; - double segLen = curr.Length(prev); + double const segLen = curr.Length(prev); if ((m_startLength != 0) && (m_endLength != 0)) { @@ -123,7 +123,7 @@ void path_points::best_filtration(m2::PointD const & pt) } } - m_length += m_prev.Length(pt); + m_length += segLen; } else { @@ -145,7 +145,8 @@ void path_points::operator() (m2::PointD const & p) bool path_points::IsExist() { // finally, assign whole length to every cutted path - for_each(m_points.begin(), m_points.end(), bind(&di::PathInfo::SetLength, _1, m_length)); + for_each(m_points.begin(), m_points.end(), + bind(&di::PathInfo::SetFullLength, _1, m_length)); EndPL(); return base_type::IsExist(); diff --git a/map/drawer_yg.cpp b/map/drawer_yg.cpp index 95a2281541..d134fbca4e 100644 --- a/map/drawer_yg.cpp +++ b/map/drawer_yg.cpp @@ -202,8 +202,8 @@ void DrawerYG::drawArea(vector const & pts, rule_ptr_t pRule, int de namespace { double const min_text_height_filtered = 2; - double const min_text_height = 12; // 8 -// double const min_text_height_mask = 9.99; // 10 + double const min_text_height = 12; // 8 + //double const min_text_height_mask = 9.99; // 10 } uint8_t DrawerYG::get_text_font_size(rule_ptr_t pRule) const @@ -258,7 +258,7 @@ bool DrawerYG::drawPathText(di::PathInfo const & info, string const & name, uint &info.m_path[0], info.m_path.size(), name, - info.GetLength(), + info.GetFullLength(), info.GetOffset(), yg::EPosCenter, yg::maxDepth); @@ -276,6 +276,7 @@ void DrawerYG::SetVisualScale(double visualScale) void DrawerYG::SetScale(int level) { + m_level = level; m_scale = scales::GetM2PFactor(level); } @@ -283,8 +284,7 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size { buffer_vector pathRules; - /// separating path rules from other - + // separating path rules from other for (unsigned i = 0; i < count; ++i) { rule_ptr_t pRule = rules[i].m_rule; @@ -301,8 +301,35 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size if (!pathRules.empty()) { + bool const isNumber = !pInfo->m_road.empty() && m_level >= 12; + for (list::const_iterator i = pInfo->m_pathes.begin(); i != pInfo->m_pathes.end(); ++i) + { drawPath(i->m_path, pathRules.data(), pathRules.size()); + + int const textHeight = 12; + m2::PointD pt; + double const length = i->GetFullLength(); + if (isNumber && (length >= (pInfo->m_road.size() + 2)*textHeight)) + { + size_t const count = size_t(length / 1000.0) + 2; + + for (size_t j = 1; j < count; ++j) + { + if (i->GetSmPoint(double(j) / double(count), pt)) + { + yg::FontDesc fontDesc( + false, + textHeight, + yg::Color(150, 75, 0, 255), // brown + true, + yg::Color(255, 255, 255, 255)); + + m_pScreen->drawText(fontDesc, pt, yg::EPosCenter, 0.0, pInfo->m_road, yg::maxDepth, true); + } + } + } + } } for (unsigned i = 0; i < count; ++i) diff --git a/map/drawer_yg.hpp b/map/drawer_yg.hpp index 982b77c006..d1e09f98ee 100644 --- a/map/drawer_yg.hpp +++ b/map/drawer_yg.hpp @@ -32,13 +32,14 @@ namespace di class DrawInfo { public: - DrawInfo(string const & name, double rank) : m_name(name), m_rank(rank) {} + DrawInfo(string const & name, string const & road, double rank) + : m_name(name), m_road(road), m_rank(rank) {} list m_pathes; list m_areas; m2::PointD m_point; - string m_name; + string m_name, m_road; double m_rank; }; @@ -60,6 +61,7 @@ class DrawerYG double m_scale; double m_visualScale; + int m_level; shared_ptr m_pScreen; shared_ptr m_pSkin; diff --git a/map/framework.cpp b/map/framework.cpp index a3c2590650..33b66944c9 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -163,6 +163,7 @@ namespace fwork shared_ptr ptr( new di::DrawInfo(f.GetPreferredDrawableName(languages::GetCurrentPriorities()), + f.GetRoadNumber(), m_zoom > 5 ? f.GetPopulationDrawRank() : 0.0)); DrawerYG * pDrawer = GetDrawer();