From b899690f3a4b2330ca823f6b9d3a19a43f341632 Mon Sep 17 00:00:00 2001 From: Mikhail Gorbushin Date: Wed, 29 May 2019 17:28:06 +0300 Subject: [PATCH] [qt] add mwms borders selection --- map/framework.cpp | 61 ++++++++++++++++++++++++++++++----- map/framework.hpp | 1 + qt/draw_widget.cpp | 39 ++++++++++++++++++---- qt/draw_widget.hpp | 4 +++ qt/mainwindow.cpp | 28 ++++++++++++++++ qt/mainwindow.hpp | 2 ++ qt/res/borders_selection.png | Bin 0 -> 3156 bytes qt/res/resources.qrc | 1 + 8 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 qt/res/borders_selection.png diff --git a/map/framework.cpp b/map/framework.cpp index d48b3eaffb..d793bd0d43 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -3470,9 +3470,9 @@ void DrawLine(Box const & box, dp::Color const & color, df::DrapeApi & drapeApi, drapeApi.AddLine(id, df::DrapeApiLineData(points, color).Width(3.0f).ShowPoints(true).ShowId()); } -void VisualizeFeatureInRect(m2::RectD const & rect, FeatureType & ft, df::DrapeApi & drapeApi, - size_t & counter) +void VisualizeFeatureInRect(m2::RectD const & rect, FeatureType & ft, df::DrapeApi & drapeApi) { + static uint64_t counter = 0; bool allPointsOutside = true; vector points; ft.ForEachPoint([&points, &rect, &allPointsOutside](m2::PointD const & pt) @@ -3497,13 +3497,59 @@ void VisualizeFeatureInRect(m2::RectD const & rect, FeatureType & ft, df::DrapeA } } // namespace +void VisualizeMwmBorder(df::DrapeApi & drapeApi, std::string const & mwmName) +{ + static std::string const kPathToBorders = + base::JoinPath(GetPlatform().ResourcesDir(), "borders"); + + std::string const path = base::JoinPath(kPathToBorders, mwmName + ".poly"); + + std::vector points; + std::ifstream input(path); + std::string line; + + std::getline(input, line); + std::getline(input, line); + + double lon = 0.0; + double lat = 0.0; + while (std::getline(input, line)) + { + if (line == "END") + break; + + strings::SimpleTokenizer iter(line, "\t"); + + if (!strings::to_double(*iter, lon)) + return; + ++iter; + + if (!strings::to_double(*iter, lat)) + return; + + points.emplace_back(MercatorBounds::FromLatLon(lat, lon)); + } + + static uint32_t kColorCounter = 0; + drapeApi.AddLine(mwmName, + df::DrapeApiLineData(points, colorList[kColorCounter]).Width(3.0f).ShowId()); + + kColorCounter = (kColorCounter + 1) % colorList.size(); +} + +void Framework::VisualizeMwmsBordersInRect(m2::RectD const & rect) +{ + auto mwmNames = m_infoGetter->GetRegionsCountryIdByRect(rect, false /* rough */); + for (auto const & mwmName : mwmNames) + VisualizeMwmBorder(m_drapeApi, mwmName); +} + void Framework::VisualizeRoadsInRect(m2::RectD const & rect) { - size_t counter = 0; - m_model.ForEachFeature(rect, [this, &counter, &rect](FeatureType & ft) + m_model.ForEachFeature(rect, [this, &rect](FeatureType & ft) { if (routing::IsRoad(feature::TypesHolder(ft))) - VisualizeFeatureInRect(rect, ft, m_drapeApi, counter); + VisualizeFeatureInRect(rect, ft, m_drapeApi); }, scales::GetUpperScale()); } @@ -3548,9 +3594,8 @@ void Framework::VisualizeCityBoundariesInRect(m2::RectD const & rect) void Framework::VisualizeCityRoadsInRect(m2::RectD const & rect) { map> cityRoads; - size_t counter = 0; GetDataSource().ForEachInRect( - [this, &rect, &cityRoads, &counter](FeatureType & ft) { + [this, &rect, &cityRoads](FeatureType & ft) { if (ft.GetGeomType() != feature::GeomType::Line) return; @@ -3568,7 +3613,7 @@ void Framework::VisualizeCityRoadsInRect(m2::RectD const & rect) if (!cityRoads[mwmId]->IsCityRoad(ft.GetID().m_index)) return; // ft is not a city road. - VisualizeFeatureInRect(rect, ft, m_drapeApi, counter); + VisualizeFeatureInRect(rect, ft, m_drapeApi); }, rect, scales::GetUpperScale()); } diff --git a/map/framework.hpp b/map/framework.hpp index f59e4e5eb4..7df79015f9 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -372,6 +372,7 @@ public: BookmarkManager const & GetBookmarkManager() const; // Utilities + void VisualizeMwmsBordersInRect(m2::RectD const & rect); void VisualizeRoadsInRect(m2::RectD const & rect); void VisualizeCityBoundariesInRect(m2::RectD const & rect); void VisualizeCityRoadsInRect(m2::RectD const & rect); diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index 407848a6da..53c8e95ba0 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -208,7 +208,7 @@ void DrawWidget::mousePressEvent(QMouseEvent * e) { SubmitBookmark(pt); } - else if (!(m_selectionMode || m_cityBoundariesSelectionMode || m_cityRoadsSelectionMode) || + else if (!(IsSelectionModeEnabled()) || IsCommandModifier(e)) { ShowInfoPopup(e, pt); @@ -233,7 +233,7 @@ void DrawWidget::mouseMoveEvent(QMouseEvent * e) if (IsLeftButton(e) && !IsAltModifier(e)) m_framework.TouchEvent(GetTouchEvent(e, df::TouchEvent::TOUCH_MOVE)); - if ((m_selectionMode || m_cityBoundariesSelectionMode || m_cityRoadsSelectionMode) && + if ((IsSelectionModeEnabled()) && m_rubberBand != nullptr && m_rubberBand->isVisible()) { m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, e->pos()).normalized()); @@ -250,7 +250,7 @@ void DrawWidget::mouseReleaseEvent(QMouseEvent * e) { m_framework.TouchEvent(GetTouchEvent(e, df::TouchEvent::TOUCH_UP)); } - else if ((m_selectionMode || m_cityBoundariesSelectionMode || m_cityRoadsSelectionMode) && + else if ((IsSelectionModeEnabled()) && IsRightButton(e) && m_rubberBand != nullptr && m_rubberBand->isVisible()) { QPoint const lt = m_rubberBand->geometry().topLeft(); @@ -262,20 +262,34 @@ void DrawWidget::mouseReleaseEvent(QMouseEvent * e) { CHECK(!m_cityBoundariesSelectionMode, ()); CHECK(!m_cityRoadsSelectionMode, ()); + CHECK(!m_mwmsBordersSelectionMode, ()); m_framework.VisualizeRoadsInRect(rect); } else if (m_cityBoundariesSelectionMode) { - CHECK(!m_selectionMode, ()); CHECK(!m_cityRoadsSelectionMode, ()); + CHECK(!m_mwmsBordersSelectionMode, ()); + CHECK(!m_selectionMode, ()); m_framework.VisualizeCityBoundariesInRect(rect); } - else // m_cityRoadsSelectionMode + else if (m_cityRoadsSelectionMode) { - CHECK(!m_selectionMode, ()); CHECK(!m_cityBoundariesSelectionMode, ()); + CHECK(!m_mwmsBordersSelectionMode, ()); + CHECK(!m_selectionMode, ()); m_framework.VisualizeCityRoadsInRect(rect); } + else if (m_mwmsBordersSelectionMode) + { + CHECK(!m_cityBoundariesSelectionMode, ()); + CHECK(!m_cityRoadsSelectionMode, ()); + CHECK(!m_selectionMode, ()); + m_framework.VisualizeMwmsBordersInRect(rect); + } + else + { + UNREACHABLE(); + } m_rubberBand->hide(); } @@ -554,6 +568,11 @@ void DrawWidget::SetCityRoadsSelectionMode(bool mode) m_cityRoadsSelectionMode = mode; } +void DrawWidget::SetMwmsBordersSelectionMode(bool mode) +{ + m_mwmsBordersSelectionMode = mode; +} + // static void DrawWidget::SetDefaultSurfaceFormat(bool apiOpenGLES3) { @@ -593,4 +612,12 @@ m2::PointD DrawWidget::GetCoordsFromSettingsIfExists(bool start, m2::PointD cons return m_framework.P3dtoG(pt); } + +bool DrawWidget::IsSelectionModeEnabled() const +{ + return m_selectionMode || + m_cityBoundariesSelectionMode || + m_cityRoadsSelectionMode || + m_mwmsBordersSelectionMode; +} } // namespace qt diff --git a/qt/draw_widget.hpp b/qt/draw_widget.hpp index 2f25165605..719620ad81 100644 --- a/qt/draw_widget.hpp +++ b/qt/draw_widget.hpp @@ -79,6 +79,7 @@ public: void SetSelectionMode(bool mode); void SetCityBoundariesSelectionMode(bool mode); void SetCityRoadsSelectionMode(bool mode); + void SetMwmsBordersSelectionMode(bool mode); RouteMarkType GetRoutePointAddMode() const { return m_routePointAddMode; } void SetRoutePointAddMode(RouteMarkType mode) { m_routePointAddMode = mode; } @@ -109,6 +110,8 @@ private: void SubmitBookmark(m2::PointD const & pt); void ShowPlacePage(place_page::Info const & info); + bool IsSelectionModeEnabled() const; + void UpdateCountryStatus(storage::CountryId const & countryId); m2::PointD GetCoordsFromSettingsIfExists(bool start, m2::PointD const & pt); @@ -124,6 +127,7 @@ private: bool m_selectionMode = false; bool m_cityBoundariesSelectionMode = false; bool m_cityRoadsSelectionMode = false; + bool m_mwmsBordersSelectionMode = false; RouteMarkType m_routePointAddMode = RouteMarkType::Finish; std::unique_ptr m_screenshoter; diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp index 6736f5fb63..3a44e75fe5 100644 --- a/qt/mainwindow.cpp +++ b/qt/mainwindow.cpp @@ -375,6 +375,11 @@ void MainWindow::CreateNavigationBar() this, SLOT(OnSwitchCityRoadsSelectionMode())); m_selectionCityRoadsMode->setCheckable(true); + m_selectionMwmsBordersMode = + pToolBar->addAction(QIcon(":/navig64/borders_selection.png"), tr("MWMs borders selection mode"), + this, SLOT(OnSwitchMwmsBordersSelectionMode())); + m_selectionMwmsBordersMode->setCheckable(true); + m_clearSelection = pToolBar->addAction(QIcon(":/navig64/clear.png"), tr("Clear selection"), this, SLOT(OnClearSelection())); m_clearSelection->setToolTip(tr("Clear selection")); @@ -608,6 +613,9 @@ void MainWindow::OnSwitchSelectionMode() m_selectionCityRoadsMode->setChecked(false); m_pDrawWidget->SetCityRoadsSelectionMode(false); + m_selectionMwmsBordersMode->setChecked(false); + m_pDrawWidget->SetMwmsBordersSelectionMode(false); + m_pDrawWidget->SetSelectionMode(m_selectionMode->isChecked()); } @@ -619,6 +627,9 @@ void MainWindow::OnSwitchCityBoundariesSelectionMode() m_selectionCityRoadsMode->setChecked(false); m_pDrawWidget->SetCityRoadsSelectionMode(false); + m_selectionMwmsBordersMode->setChecked(false); + m_pDrawWidget->SetMwmsBordersSelectionMode(false); + m_pDrawWidget->SetCityBoundariesSelectionMode(m_selectionCityBoundariesMode->isChecked()); } @@ -630,9 +641,26 @@ void MainWindow::OnSwitchCityRoadsSelectionMode() m_selectionCityBoundariesMode->setChecked(false); m_pDrawWidget->SetCityBoundariesSelectionMode(false); + m_selectionMwmsBordersMode->setChecked(false); + m_pDrawWidget->SetMwmsBordersSelectionMode(false); + m_pDrawWidget->SetCityRoadsSelectionMode(m_selectionCityRoadsMode->isChecked()); } +void MainWindow::OnSwitchMwmsBordersSelectionMode() +{ + m_selectionMode->setChecked(false); + m_pDrawWidget->SetSelectionMode(false); + + m_selectionCityBoundariesMode->setChecked(false); + m_pDrawWidget->SetCityBoundariesSelectionMode(false); + + m_selectionCityRoadsMode->setChecked(false); + m_pDrawWidget->SetCityRoadsSelectionMode(false); + + m_pDrawWidget->SetMwmsBordersSelectionMode(m_selectionMwmsBordersMode->isChecked()); +} + void MainWindow::OnClearSelection() { m_pDrawWidget->GetFramework().GetDrapeApi().Clear(); diff --git a/qt/mainwindow.hpp b/qt/mainwindow.hpp index 81bea0f366..b7c20cfc75 100644 --- a/qt/mainwindow.hpp +++ b/qt/mainwindow.hpp @@ -49,6 +49,7 @@ class MainWindow : public QMainWindow, location::LocationObserver QAction * m_bookmarksAction = nullptr; QAction * m_selectionCityBoundariesMode = nullptr; QAction * m_selectionCityRoadsMode = nullptr; + QAction * m_selectionMwmsBordersMode = nullptr; QToolButton * m_routePointsToolButton = nullptr; QAction * m_selectStartRoutePoint = nullptr; QAction * m_selectFinishRoutePoint = nullptr; @@ -112,6 +113,7 @@ protected Q_SLOTS: void OnSwitchSelectionMode(); void OnSwitchCityBoundariesSelectionMode(); void OnSwitchCityRoadsSelectionMode(); + void OnSwitchMwmsBordersSelectionMode(); void OnClearSelection(); void OnTrafficEnabled(); diff --git a/qt/res/borders_selection.png b/qt/res/borders_selection.png new file mode 100644 index 0000000000000000000000000000000000000000..7ea9c4f32820c52de16a038845361b01239d29b9 GIT binary patch literal 3156 zcmV-a46E~rP)00001b5ch_0olnc ze*gds4oO5oRCt`#n%8q1#~Hx+C*?U0$y?qsnaNB%89yXW;!NT)6OEm*Tp~-h)!ZUc z5(@~hp!ePZ0*6X;+#Rm>I}iW?P&J;sXFHoo9-JtkfWN#RD35*wDw~%4y`5HY ztT~{!DPWL9cxuP8f{8K)ar7Sx{v&=JVIVwQ= zrbx6;)$jQLM6!Vh%p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