From 485b4c6f3ecb4dcab3d2262df18d820f20dca6cb Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Mon, 11 Dec 2017 17:01:02 +0300 Subject: [PATCH] [OpenLR-tool] Mark matched path as golden. --- .../openlr_assessment_tool/mainwindow.cpp | 5 ++ .../openlr_assessment_tool/mainwindow.hpp | 1 + .../openlr_assessment_tool/traffic_mode.cpp | 62 +++++++++++++------ .../openlr_assessment_tool/traffic_mode.hpp | 2 + 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp index 499945ccde..f71a108f36 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp @@ -273,6 +273,8 @@ MainWindow::MainWindow(Framework & framework, std::string const & url, std::stri fileMenu->addSeparator(); + m_goldifyMatchedPathAction = fileMenu->addAction( + "Goldify", [this] { m_trafficMode->GoldifyMatchedPath(); }, QKeySequence("Ctrl+G")); m_startEditingAction = fileMenu->addAction("Edit", [this] { m_trafficMode->StartBuildingPath(); @@ -300,6 +302,7 @@ MainWindow::MainWindow(Framework & framework, std::string const & url, std::stri }, QKeySequence("Ctrl+I")); + m_goldifyMatchedPathAction->setEnabled(false /* enabled */); m_closeTrafficSampleAction->setEnabled(false /* enabled */); m_saveTrafficSampleAction->setEnabled(false /* enabled */); m_startEditingAction->setEnabled(false /* enabled */); @@ -361,6 +364,7 @@ void MainWindow::OnOpenTrafficSample() return; } + m_goldifyMatchedPathAction->setEnabled(true /* enabled */); m_closeTrafficSampleAction->setEnabled(true /* enabled */); m_saveTrafficSampleAction->setEnabled(true /* enabled */); m_startEditingAction->setEnabled(true /* enabled */); @@ -373,6 +377,7 @@ void MainWindow::OnCloseTrafficSample() // If not saved, ask a user if he/she wants to save. // OnSaveTrafficSample() + m_goldifyMatchedPathAction->setEnabled(false /* enabled */); m_saveTrafficSampleAction->setEnabled(false /* enabled */); m_closeTrafficSampleAction->setEnabled(false /* enabled */); m_startEditingAction->setEnabled(false /* enabled */); diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.hpp b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.hpp index 3aaa0c80f3..2777fd6f6c 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.hpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.hpp @@ -49,6 +49,7 @@ private: openlr::TrafficMode * m_trafficMode = nullptr; QDockWidget * m_docWidget = nullptr; + QAction * m_goldifyMatchedPathAction = nullptr; QAction * m_saveTrafficSampleAction = nullptr; QAction * m_closeTrafficSampleAction = nullptr; QAction * m_startEditingAction = nullptr; diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp index f1cfc4e809..30d428d118 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp @@ -268,29 +268,33 @@ Qt::ItemFlags TrafficMode::flags(QModelIndex const & index) const return QAbstractItemModel::flags(index); } +void TrafficMode::GoldifyMatchedPath() +{ + if (!m_currentSegment->HasMatchedPath()) + { + QMessageBox::information(nullptr /* parent */, "Error", + "The selected segment does not have a matched path"); + return; + } + + if (!StartBuildingPathChecks()) + return; + + m_currentSegment->SetGoldenPath(m_currentSegment->GetMatchedPath()); + m_goldenPath.clear(); + m_drawerDelegate->DrawGoldenPath(GetPoints(m_currentSegment->GetGoldenPath())); +} + void TrafficMode::StartBuildingPath() { - CHECK(m_currentSegment, ("A segment should be selected before path building is started.")); - - if (m_buildingPath) - MYTHROW(TrafficModeError, ("Path building already in progress.")); - - if (m_currentSegment->HasGoldenPath()) - { - auto const btn = QMessageBox::question( - nullptr, - "Override warning", - "The selected segment already has a golden path. Do you want to override?"); - if (btn == QMessageBox::No) - return; - } + if (!StartBuildingPathChecks()) + return; m_currentSegment->SetGoldenPath({}); m_buildingPath = true; m_drawerDelegate->ClearGoldenPath(); - m_drawerDelegate->VisualizePoints( - m_pointsDelegate->GetAllJunctionPointsInViewport()); + m_drawerDelegate->VisualizePoints(m_pointsDelegate->GetAllJunctionPointsInViewport()); } void TrafficMode::PushPoint(m2::PointD const & coord, std::vector const & points) @@ -382,10 +386,9 @@ void TrafficMode::IgnorePath() if (m_currentSegment->HasGoldenPath()) { - auto const btn = QMessageBox::question( - nullptr, - "Override warning", - "The selected segment has a golden path. Do you want to discard it?"); + auto const btn = + QMessageBox::question(nullptr /* parent */, "Override warning", + "The selected segment has a golden path. Do you want to discard it?"); if (btn == QMessageBox::No) return; } @@ -502,4 +505,23 @@ void TrafficMode::HandlePoint(m2::PointD clickPoint, Qt::MouseButton const butto return; } } + +bool TrafficMode::StartBuildingPathChecks() const +{ + CHECK(m_currentSegment, ("A segment should be selected before path building is started.")); + + if (m_buildingPath) + MYTHROW(TrafficModeError, ("Path building already in progress.")); + + if (m_currentSegment->HasGoldenPath()) + { + auto const btn = QMessageBox::question( + nullptr /* parent */, "Override warning", + "The selected segment already has a golden path. Do you want to override?"); + if (btn == QMessageBox::No) + return false; + } + + return true; +} } // namespace openlr diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp index a2dc9bdd87..2a823ca751 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp @@ -84,6 +84,7 @@ public: Qt::ItemFlags flags(QModelIndex const & index) const Q_DECL_OVERRIDE; bool IsBuildingPath() const { return m_buildingPath; } + void GoldifyMatchedPath(); void StartBuildingPath(); void PushPoint(m2::PointD const & coord, std::vector const & points); @@ -110,6 +111,7 @@ signals: private: void HandlePoint(m2::PointD clickPoint, Qt::MouseButton const button); + bool StartBuildingPathChecks() const; Index const & m_index; std::vector m_segments;