2019-12-31 18:56:34 +08:00
/**
******************************************************************************
*
* @file mapripper.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A class that allows ripping of a selection of the map
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
# include "mapripper.h"
namespace mapcontrol {
2022-07-29 01:43:16 +08:00
MapRipper : : MapRipper ( internals : : Core * core , const internals : : RectLatLng & rect , int const & maxz ) : sleep ( 1 ) , cancel ( false ) , core ( core ) , yesToAll ( true )
2019-12-31 18:56:34 +08:00
{
if ( ! rect . IsEmpty ( ) ) {
type = core - > GetMapType ( ) ;
2022-07-29 01:43:16 +08:00
//progressForm = new MapRipForm;
//connect(progressForm, SIGNAL(cancelRequest()), this, SLOT(stopFetching()));
2019-12-31 18:56:34 +08:00
area = rect ;
zoom = core - > Zoom ( ) ;
2022-07-29 01:43:16 +08:00
setMaxZoom ( maxz ) ;
2019-12-31 18:56:34 +08:00
points = core - > Projection ( ) - > GetAreaTileList ( area , zoom , 0 ) ;
this - > start ( ) ;
cancel = false ;
2022-07-29 01:43:16 +08:00
//progressForm->show();
//connect(this, SIGNAL(percentageChanged(int)), progressForm, SLOT(SetPercentage(int)));
//connect(this, SIGNAL(numberOfTilesChanged(int, int)), progressForm, SLOT(SetNumberOfTiles(int, int)));
//connect(this, SIGNAL(providerChanged(QString, int)), progressForm, SLOT(SetProvider(QString, int)));
2019-12-31 18:56:34 +08:00
connect ( this , SIGNAL ( finished ( ) ) , this , SLOT ( finish ( ) ) ) ;
emit numberOfTilesChanged ( 0 , 0 ) ;
} else
# ifdef Q_OS_DARWIN
{ QMessageBox : : information ( new QWidget ( ) , tr ( " No valid selection " ) , tr ( " This pre-caches map data. \n \n Please first select the area of the map to rip with <COMMAND>+Left mouse click " ) ) ; }
# else
{ QMessageBox : : information ( new QWidget ( ) , tr ( " No valid selection " ) , tr ( " This pre-caches map data. \n \n Please first select the area of the map to rip with <CTRL>+Left mouse click " ) ) ; }
# endif
}
void MapRipper : : finish ( )
{
2022-07-29 01:43:16 +08:00
2019-12-31 18:56:34 +08:00
if ( zoom < maxzoom & & ! cancel ) {
+ + zoom ;
2022-07-29 01:43:16 +08:00
int ret = QMessageBox : : Yes ;
2019-12-31 18:56:34 +08:00
if ( ! yesToAll ) {
QMessageBox msgBox ;
msgBox . setText ( QString ( tr ( " Continue Ripping at zoom level %1? " ) ) . arg ( zoom ) ) ;
// msgBox.setInformativeText("Do you want to save your changes?");
msgBox . setStandardButtons ( QMessageBox : : Yes | QMessageBox : : No | QMessageBox : : YesAll ) ;
msgBox . setDefaultButton ( QMessageBox : : Yes ) ;
ret = msgBox . exec ( ) ;
} else {
ret = QMessageBox : : Yes ;
}
2022-07-29 01:43:16 +08:00
2019-12-31 18:56:34 +08:00
if ( ret = = QMessageBox : : Yes ) {
points . clear ( ) ;
points = core - > Projection ( ) - > GetAreaTileList ( area , zoom , 0 ) ;
2022-07-29 01:43:16 +08:00
//qDebug() << zoom << maxzoom << ret;
2019-12-31 18:56:34 +08:00
this - > start ( ) ;
} else if ( ret = = QMessageBox : : YesAll ) {
yesToAll = true ;
points . clear ( ) ;
points = core - > Projection ( ) - > GetAreaTileList ( area , zoom , 0 ) ;
this - > start ( ) ;
2022-07-29 01:43:16 +08:00
2019-12-31 18:56:34 +08:00
} else {
2022-07-29 01:43:16 +08:00
//progressForm->close();
//delete progressForm;
emit ripfinished ( ) ;
2019-12-31 18:56:34 +08:00
this - > deleteLater ( ) ;
}
} else {
2022-07-29 01:43:16 +08:00
//yesToAll = false;
//progressForm->close();
//delete progressForm;
emit ripfinished ( ) ;
2019-12-31 18:56:34 +08:00
this - > deleteLater ( ) ;
}
}
void MapRipper : : run ( )
{
int countOk = 0 ;
bool goodtile = false ;
// Stuff.Shuffle<Point>(ref list);
QVector < core : : MapType : : Types > types = OPMaps : : Instance ( ) - > GetAllLayersOfType ( type ) ;
int all = points . count ( ) ;
for ( int i = 0 ; i < all ; i + + ) {
emit numberOfTilesChanged ( all , i + 1 ) ;
if ( cancel ) {
break ;
}
core : : Point p = points [ i ] ;
{
2022-07-29 01:43:16 +08:00
//qDebug()<<"offline fetching:"<<p.ToString();
2019-12-31 18:56:34 +08:00
foreach ( core : : MapType : : Types type , types ) {
emit providerChanged ( core : : MapType : : StrByType ( type ) , zoom ) ;
QByteArray img = OPMaps : : Instance ( ) - > GetImageFrom ( type , p , zoom ) ;
2022-07-29 01:43:16 +08:00
//qDebug() << img;
2021-01-20 20:30:59 +08:00
2019-12-31 18:56:34 +08:00
if ( img . length ( ) ! = 0 ) {
goodtile = true ;
img = NULL ;
} else {
goodtile = false ;
}
}
if ( goodtile ) {
countOk + + ;
} else {
i - - ;
2022-07-29 01:43:16 +08:00
QThread : : msleep ( 1 ) ;
2019-12-31 18:56:34 +08:00
continue ;
}
}
emit percentageChanged ( ( int ) ( ( i + 1 ) * 100 / all ) ) ; // , i+1);
// worker.ReportProgress((int) ((i+1)*100/all), i+1);
QThread : : msleep ( sleep ) ;
}
}
void MapRipper : : stopFetching ( )
{
QMutexLocker locker ( & mutex ) ;
cancel = true ;
}
2022-07-29 01:43:16 +08:00
void MapRipper : : setMaxZoom ( int const & zoom )
{
if ( zoom < = core - > MaxZoom ( ) )
{
maxzoom = zoom ;
}
else
{
maxzoom = core - > MaxZoom ( ) ;
}
}
2019-12-31 18:56:34 +08:00
}