forked from organicmaps/organicmaps
[qt] add option - draw borders from packed_polygon.bin
This commit is contained in:
parent
64e4c4ebe7
commit
4025f9f9f1
7 changed files with 203 additions and 63 deletions
|
@ -241,7 +241,7 @@ void GeneratePackedBorders(std::string const & baseDir)
|
|||
}
|
||||
|
||||
void DumpBorderToPolyFile(std::string const & targetDir, storage::CountryId const & mwmName,
|
||||
std::vector<std::vector<m2::PointD>> const & polygons)
|
||||
std::vector<m2::RegionD> const & polygons)
|
||||
{
|
||||
CHECK(!polygons.empty(), ());
|
||||
|
||||
|
@ -255,7 +255,7 @@ void DumpBorderToPolyFile(std::string const & targetDir, storage::CountryId cons
|
|||
{
|
||||
poly << polygonId << std::endl;
|
||||
++polygonId;
|
||||
for (auto const & point : points)
|
||||
for (auto const & point : points.Data())
|
||||
{
|
||||
ms::LatLon const ll = MercatorBounds::ToLatLon(point);
|
||||
poly << " " << std::scientific << ll.m_lon << " " << ll.m_lat << std::endl;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "storage/storage_defines.hpp"
|
||||
|
||||
#include "coding/geometry_coding.hpp"
|
||||
#include "coding/reader.hpp"
|
||||
|
||||
#include "geometry/rect2d.hpp"
|
||||
#include "geometry/region2d.hpp"
|
||||
|
@ -68,21 +69,21 @@ bool LoadCountriesList(std::string const & baseDir, CountriesContainer & countri
|
|||
void GeneratePackedBorders(std::string const & baseDir);
|
||||
|
||||
template <typename Source>
|
||||
std::vector<std::vector<m2::PointD>> ReadPolygonsOfOneBorder(Source & src)
|
||||
std::vector<m2::RegionD> ReadPolygonsOfOneBorder(Source & src)
|
||||
{
|
||||
auto const count = ReadVarUint<uint32_t>(src);
|
||||
std::vector<std::vector<m2::PointD>> result(count);
|
||||
std::vector<m2::RegionD> result(count);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
std::vector<m2::PointD> points;
|
||||
serial::LoadOuterPath(src, serial::GeometryCodingParams(), points);
|
||||
result[i] = std::move(points);
|
||||
result[i] = m2::RegionD(std::move(points));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void DumpBorderToPolyFile(std::string const & filePath, storage::CountryId const & mwmName,
|
||||
std::vector<std::vector<m2::PointD>> const & polygons);
|
||||
std::vector<m2::RegionD> const & polygons);
|
||||
void UnpackBorders(std::string const & baseDir, std::string const & targetDir);
|
||||
} // namespace borders
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "qt/create_feature_dialog.hpp"
|
||||
#include "qt/draw_widget.hpp"
|
||||
|
||||
#include "qt/create_feature_dialog.hpp"
|
||||
#include "qt/editor_dialog.hpp"
|
||||
#include "qt/place_page_dialog.hpp"
|
||||
#include "qt/qt_common/helpers.hpp"
|
||||
|
@ -16,6 +17,7 @@
|
|||
|
||||
#include "routing/routing_callbacks.hpp"
|
||||
|
||||
#include "storage/country_decl.hpp"
|
||||
#include "storage/storage_defines.hpp"
|
||||
|
||||
#include "indexer/editable_map_object.hpp"
|
||||
|
@ -24,9 +26,14 @@
|
|||
#include "platform/platform.hpp"
|
||||
#include "platform/settings.hpp"
|
||||
|
||||
#include "coding/reader.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/file_name_utils.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
|
@ -38,7 +45,8 @@
|
|||
#include <QtCore/QLocale>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QTimer>
|
||||
#include <base/file_name_utils.hpp>
|
||||
|
||||
#include "defines.hpp"
|
||||
|
||||
using namespace qt::common;
|
||||
|
||||
|
@ -212,8 +220,7 @@ void DrawWidget::mousePressEvent(QMouseEvent * e)
|
|||
{
|
||||
SubmitBookmark(pt);
|
||||
}
|
||||
else if (!(m_currentSelectionMode) ||
|
||||
IsCommandModifier(e))
|
||||
else if (!m_currentSelectionMode || IsCommandModifier(e))
|
||||
{
|
||||
ShowInfoPopup(e, pt);
|
||||
}
|
||||
|
@ -237,26 +244,53 @@ void DrawWidget::mouseMoveEvent(QMouseEvent * e)
|
|||
if (IsLeftButton(e) && !IsAltModifier(e))
|
||||
m_framework.TouchEvent(GetTouchEvent(e, df::TouchEvent::TOUCH_MOVE));
|
||||
|
||||
if ((m_currentSelectionMode) &&
|
||||
m_rubberBand != nullptr && m_rubberBand->isVisible())
|
||||
if (m_currentSelectionMode && m_rubberBand != nullptr && m_rubberBand->isVisible())
|
||||
{
|
||||
m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, e->pos()).normalized());
|
||||
}
|
||||
}
|
||||
|
||||
void DrawWidget::VisualizeMwmsBordersInRect(m2::RectD const & rect, bool withPoints)
|
||||
void DrawWidget::VisualizeMwmsBordersInRect(m2::RectD const & rect, bool withPoints,
|
||||
bool fromPackedPolygon)
|
||||
{
|
||||
static std::string const kPathToBorders =
|
||||
base::JoinPath(GetPlatform().ResourcesDir(), "borders");
|
||||
auto const getPolygons = [&](std::string const & mwmName)
|
||||
{
|
||||
if (fromPackedPolygon)
|
||||
{
|
||||
std::vector<storage::CountryDef> countries;
|
||||
FilesContainerR reader(base::JoinPath(GetPlatform().ResourcesDir(), PACKED_POLYGONS_FILE));
|
||||
ReaderSource<ModelReaderPtr> src(reader.GetReader(PACKED_POLYGONS_INFO_TAG));
|
||||
rw::Read(src, countries);
|
||||
|
||||
for (size_t id = 0; id < countries.size(); ++id)
|
||||
{
|
||||
if (countries[id].m_countryId != mwmName)
|
||||
continue;
|
||||
|
||||
src = reader.GetReader(std::to_string(id));
|
||||
return borders::ReadPolygonsOfOneBorder(src);
|
||||
}
|
||||
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string const bordersDir =
|
||||
base::JoinPath(GetPlatform().ResourcesDir(), BORDERS_DIR);
|
||||
|
||||
std::string const path = base::JoinPath(bordersDir, mwmName + BORDERS_EXTENSION);
|
||||
std::vector<m2::RegionD> polygons;
|
||||
borders::LoadBorders(path, polygons);
|
||||
|
||||
return polygons;
|
||||
}
|
||||
};
|
||||
|
||||
auto const mwmNames = m_framework.GetRegionsCountryIdByRect(rect, false /* rough */);
|
||||
|
||||
for (auto const & mwmName : mwmNames)
|
||||
{
|
||||
std::string const path = base::JoinPath(kPathToBorders, mwmName + ".poly");
|
||||
std::vector<m2::RegionD> polygons;
|
||||
borders::LoadBorders(path, polygons);
|
||||
|
||||
auto const polygons = getPolygons(mwmName);
|
||||
m_framework.DrawMwmBorder(mwmName, polygons, withPoints);
|
||||
}
|
||||
}
|
||||
|
@ -271,8 +305,8 @@ void DrawWidget::mouseReleaseEvent(QMouseEvent * e)
|
|||
{
|
||||
m_framework.TouchEvent(GetTouchEvent(e, df::TouchEvent::TOUCH_UP));
|
||||
}
|
||||
else if ((m_currentSelectionMode) &&
|
||||
IsRightButton(e) && m_rubberBand != nullptr && m_rubberBand->isVisible())
|
||||
else if (m_currentSelectionMode && IsRightButton(e) &&
|
||||
m_rubberBand != nullptr && m_rubberBand->isVisible())
|
||||
{
|
||||
QPoint const lt = m_rubberBand->geometry().topLeft();
|
||||
QPoint const rb = m_rubberBand->geometry().bottomRight();
|
||||
|
@ -296,14 +330,24 @@ void DrawWidget::mouseReleaseEvent(QMouseEvent * e)
|
|||
m_framework.VisualizeCityRoadsInRect(rect);
|
||||
break;
|
||||
}
|
||||
case SelectionMode::MwmsBorders:
|
||||
case SelectionMode::MwmsBordersByPolyFiles:
|
||||
{
|
||||
VisualizeMwmsBordersInRect(rect, false /* withPoints */);
|
||||
VisualizeMwmsBordersInRect(rect, false /* withPoints */, false /* fromPackedPolygon */);
|
||||
break;
|
||||
}
|
||||
case SelectionMode::MwmsBordersWithPoints:
|
||||
case SelectionMode::MwmsBordersWithPointsByPolyFiles:
|
||||
{
|
||||
VisualizeMwmsBordersInRect(rect, true /* withPoints */);
|
||||
VisualizeMwmsBordersInRect(rect, true /* withPoints */, false /* fromPackedPolygon */);
|
||||
break;
|
||||
}
|
||||
case SelectionMode::MwmsBordersByPackedPolygon:
|
||||
{
|
||||
VisualizeMwmsBordersInRect(rect, false /* withPoints */, true /* fromPackedPolygon */);
|
||||
break;
|
||||
}
|
||||
case SelectionMode::MwmsBordersWithPointsByPackedPolygon:
|
||||
{
|
||||
VisualizeMwmsBordersInRect(rect, true /* withPoints */, true /* fromPackedPolygon */);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -109,7 +109,7 @@ private:
|
|||
|
||||
void UpdateCountryStatus(storage::CountryId const & countryId);
|
||||
|
||||
void VisualizeMwmsBordersInRect(m2::RectD const & rect, bool withPoints);
|
||||
void VisualizeMwmsBordersInRect(m2::RectD const & rect, bool withPoints, bool fromPackedPolygon);
|
||||
|
||||
m2::PointD GetCoordsFromSettingsIfExists(bool start, m2::PointD const & pt);
|
||||
|
||||
|
@ -127,8 +127,10 @@ public:
|
|||
Features,
|
||||
CityBoundaries,
|
||||
CityRoads,
|
||||
MwmsBorders,
|
||||
MwmsBordersWithPoints
|
||||
MwmsBordersByPolyFiles,
|
||||
MwmsBordersWithPointsByPolyFiles,
|
||||
MwmsBordersByPackedPolygon,
|
||||
MwmsBordersWithPointsByPackedPolygon
|
||||
};
|
||||
|
||||
void SetSelectionMode(SelectionMode mode) { m_currentSelectionMode = {mode}; }
|
||||
|
|
|
@ -271,6 +271,14 @@ void FormatMapSize(uint64_t sizeInBytes, string & units, size_t & sizeToDownload
|
|||
units = "B";
|
||||
}
|
||||
}
|
||||
|
||||
bool IsMwmsBordersSelectionMode(DrawWidget::SelectionMode mode)
|
||||
{
|
||||
return mode == DrawWidget::SelectionMode::MwmsBordersByPolyFiles ||
|
||||
mode == DrawWidget::SelectionMode::MwmsBordersWithPointsByPolyFiles ||
|
||||
mode == DrawWidget::SelectionMode::MwmsBordersByPackedPolygon ||
|
||||
mode == DrawWidget::SelectionMode::MwmsBordersWithPointsByPackedPolygon;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void MainWindow::CreateNavigationBar()
|
||||
|
@ -639,11 +647,10 @@ void MainWindow::OnSwitchMwmsBordersSelectionMode()
|
|||
{
|
||||
MwmsBordersSelection dlg(this);
|
||||
auto const response = dlg.ShowModal();
|
||||
if (response == MwmsBordersSelection::Response::Canceled)
|
||||
if (response == MwmsBordersSelection::Response::Cancelled)
|
||||
{
|
||||
if (m_pDrawWidget->SelectionModeIsSet() &&
|
||||
(m_pDrawWidget->GetSelectionMode() == DrawWidget::SelectionMode::MwmsBordersWithPoints ||
|
||||
m_pDrawWidget->GetSelectionMode() == DrawWidget::SelectionMode::MwmsBorders))
|
||||
IsMwmsBordersSelectionMode(m_pDrawWidget->GetSelectionMode()))
|
||||
{
|
||||
m_pDrawWidget->DropSelectionMode();
|
||||
}
|
||||
|
@ -652,8 +659,10 @@ void MainWindow::OnSwitchMwmsBordersSelectionMode()
|
|||
return;
|
||||
}
|
||||
|
||||
CHECK(response == MwmsBordersSelection::Response::JustBorders ||
|
||||
response == MwmsBordersSelection::Response::WithPointsAndBorders, ());
|
||||
CHECK(response == MwmsBordersSelection::Response::JustBordersByPolyFiles ||
|
||||
response == MwmsBordersSelection::Response::WithPointsAndBordersByPolyFiles ||
|
||||
response == MwmsBordersSelection::Response::JustBordersByPackedPolygon ||
|
||||
response == MwmsBordersSelection::Response::WithPointsAndBordersByPackedPolygon, ());
|
||||
|
||||
m_selectionMode->setChecked(false);
|
||||
m_selectionCityBoundariesMode->setChecked(false);
|
||||
|
@ -661,10 +670,31 @@ void MainWindow::OnSwitchMwmsBordersSelectionMode()
|
|||
|
||||
m_selectionMwmsBordersMode->setChecked(true);
|
||||
|
||||
if (response == MwmsBordersSelection::Response::WithPointsAndBorders)
|
||||
m_pDrawWidget->SetSelectionMode(DrawWidget::SelectionMode::MwmsBordersWithPoints);
|
||||
else
|
||||
m_pDrawWidget->SetSelectionMode(DrawWidget::SelectionMode::MwmsBorders);
|
||||
switch (response)
|
||||
{
|
||||
case MwmsBordersSelection::Response::JustBordersByPolyFiles:
|
||||
{
|
||||
m_pDrawWidget->SetSelectionMode(DrawWidget::SelectionMode::MwmsBordersByPolyFiles);
|
||||
break;
|
||||
}
|
||||
case MwmsBordersSelection::Response::WithPointsAndBordersByPolyFiles:
|
||||
{
|
||||
m_pDrawWidget->SetSelectionMode(DrawWidget::SelectionMode::MwmsBordersWithPointsByPolyFiles);
|
||||
break;
|
||||
}
|
||||
case MwmsBordersSelection::Response::JustBordersByPackedPolygon:
|
||||
{
|
||||
m_pDrawWidget->SetSelectionMode(DrawWidget::SelectionMode::MwmsBordersByPackedPolygon);
|
||||
break;
|
||||
}
|
||||
case MwmsBordersSelection::Response::WithPointsAndBordersByPackedPolygon:
|
||||
{
|
||||
m_pDrawWidget->SetSelectionMode(DrawWidget::SelectionMode::MwmsBordersWithPointsByPackedPolygon);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::OnClearSelection()
|
||||
|
|
|
@ -5,50 +5,105 @@
|
|||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QRadioButton>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
#include <QtWidgets/QSplitter>
|
||||
|
||||
namespace qt
|
||||
{
|
||||
MwmsBordersSelection::MwmsBordersSelection(QWidget * parent)
|
||||
: QDialog(parent),
|
||||
m_form(this)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowTitle("Mwms borders selection settings");
|
||||
|
||||
m_radioWithPoints = new QRadioButton(tr("Show borders with points."));
|
||||
m_radioJustBorders = new QRadioButton(tr("Show just borders."));
|
||||
auto * grid = new QGridLayout;
|
||||
grid->addWidget(CreateSourceChoosingGroup(), 0, 0);
|
||||
grid->addWidget(CreateViewTypeGroup(), 1, 0);
|
||||
grid->addWidget(CreateButtonBoxGroup(), 2, 0);
|
||||
|
||||
m_radioJustBorders->setChecked(true);
|
||||
|
||||
auto * vbox = new QVBoxLayout;
|
||||
vbox->addWidget(m_radioWithPoints);
|
||||
vbox->addWidget(m_radioJustBorders);
|
||||
|
||||
m_form.addRow(vbox);
|
||||
AddButtonBox();
|
||||
setLayout(grid);
|
||||
}
|
||||
|
||||
void MwmsBordersSelection::AddButtonBox()
|
||||
QGroupBox * MwmsBordersSelection::CreateButtonBoxGroup()
|
||||
{
|
||||
auto * groupBox = new QGroupBox();
|
||||
|
||||
auto * buttonBox =
|
||||
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||
|
||||
m_form.addRow(buttonBox);
|
||||
auto * vbox = new QVBoxLayout;
|
||||
|
||||
vbox->addWidget(buttonBox);
|
||||
groupBox->setLayout(vbox);
|
||||
groupBox->setFlat(true);
|
||||
|
||||
QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
return groupBox;
|
||||
}
|
||||
|
||||
MwmsBordersSelection::Response MwmsBordersSelection::ShowModal()
|
||||
{
|
||||
if (exec() != QDialog::Accepted)
|
||||
return Response::Canceled;
|
||||
return Response::Cancelled;
|
||||
|
||||
if (m_radioJustBorders->isChecked())
|
||||
return Response::JustBorders;
|
||||
if (m_radioBordersFromData->isChecked())
|
||||
{
|
||||
if (m_radioJustBorders->isChecked())
|
||||
return Response::JustBordersByPolyFiles;
|
||||
|
||||
if (m_radioWithPoints->isChecked())
|
||||
return Response::WithPointsAndBorders;
|
||||
if (m_radioWithPoints->isChecked())
|
||||
return Response::WithPointsAndBordersByPolyFiles;
|
||||
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
if (m_radioBordersFromPackedPolygon->isChecked())
|
||||
{
|
||||
if (m_radioJustBorders->isChecked())
|
||||
return Response::JustBordersByPackedPolygon;
|
||||
|
||||
if (m_radioWithPoints->isChecked())
|
||||
return Response::WithPointsAndBordersByPackedPolygon;
|
||||
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
QGroupBox * MwmsBordersSelection::CreateSourceChoosingGroup()
|
||||
{
|
||||
auto * groupBox = new QGroupBox();
|
||||
|
||||
m_radioBordersFromPackedPolygon = new QRadioButton(tr("Show borders from packed_polygon.bin."));
|
||||
m_radioBordersFromData = new QRadioButton(tr("Show borders from *.poly files."));
|
||||
|
||||
m_radioBordersFromPackedPolygon->setChecked(true);
|
||||
|
||||
auto * vbox = new QVBoxLayout;
|
||||
|
||||
vbox->addWidget(m_radioBordersFromPackedPolygon);
|
||||
vbox->addWidget(m_radioBordersFromData);
|
||||
groupBox->setLayout(vbox);
|
||||
|
||||
return groupBox;
|
||||
}
|
||||
|
||||
QGroupBox * MwmsBordersSelection::CreateViewTypeGroup()
|
||||
{
|
||||
auto * groupBox = new QGroupBox();
|
||||
|
||||
m_radioWithPoints = new QRadioButton(tr("Show borders with points."));
|
||||
m_radioJustBorders = new QRadioButton(tr("Show just borders."));
|
||||
|
||||
m_radioWithPoints->setChecked(true);
|
||||
|
||||
auto * vbox = new QVBoxLayout;
|
||||
|
||||
vbox->addWidget(m_radioWithPoints);
|
||||
vbox->addWidget(m_radioJustBorders);
|
||||
groupBox->setLayout(vbox);
|
||||
|
||||
return groupBox;
|
||||
}
|
||||
} // namespace qt
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QFormLayout>
|
||||
#include <QtWidgets/QGroupBox>
|
||||
#include <QtWidgets/QRadioButton>
|
||||
|
||||
#include <string>
|
||||
|
||||
class Framework;
|
||||
|
||||
namespace qt
|
||||
|
@ -18,18 +19,25 @@ public:
|
|||
|
||||
enum class Response
|
||||
{
|
||||
JustBorders,
|
||||
WithPointsAndBorders,
|
||||
JustBordersByPolyFiles,
|
||||
WithPointsAndBordersByPolyFiles,
|
||||
|
||||
Canceled
|
||||
JustBordersByPackedPolygon,
|
||||
WithPointsAndBordersByPackedPolygon,
|
||||
|
||||
Cancelled
|
||||
};
|
||||
|
||||
Response ShowModal();
|
||||
|
||||
private:
|
||||
void AddButtonBox();
|
||||
QGroupBox * CreateSourceChoosingGroup();
|
||||
QGroupBox * CreateViewTypeGroup();
|
||||
QGroupBox * CreateButtonBoxGroup();
|
||||
|
||||
QRadioButton * m_radioBordersFromPackedPolygon;
|
||||
QRadioButton * m_radioBordersFromData;
|
||||
|
||||
QFormLayout m_form;
|
||||
QRadioButton * m_radioWithPoints;
|
||||
QRadioButton * m_radioJustBorders;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue