Example #1
0
 virtual void grid(GridBase<CELL, 3> *ret)
 {
     CoordBox<3> box = ret->boundingBox();
     for (CoordBox<3>::Iterator i = box.begin(); i != box.end(); ++i) {
         ret->at(*i) = CELL(*i);
     }
 }
Example #2
0
    virtual void grid(GridType *grid)
    {
        CoordBox<2> box = grid->boundingBox();
        grid->setEdge(ContainerCellType());

        for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) {
            // IDs are derived from a counter. Resetting it ensures
            // that the initializer will use the same ID for a
            // particle on each node for any given container cell:
            counter = 1 + i->toIndex(box.dimensions) * numCells;

            ContainerCellType cell = grid->get(*i);
            cell.clear();
            grid->set(*i, cell);

            if (*i == Coord<2>(0, 0)) {
                // add a single cell with an influx of 1. this will
                // make the whole system heat up over time.
                addHeater(grid, Coord<2>(0, 0), FloatCoord<2>(0, 0), 0, 1);
            }

            addRandomCells(grid, *i, numCells);
        }

        fillGeometryData(grid);
    }
Example #3
0
    void Initializer::grid(LibGeoDecomp::GridBase<Cell, 2> *ret)
    {
        using LibGeoDecomp::CoordBox;
        using LibGeoDecomp::FloatCoord;

        boost::gil::rgb8_image_t img;
        boost::gil::png_read_image(VANDOUKEN_DATA_DIR VANDOUKEN_INITIALIZER_IMG, img);
        boost::gil::rgb8_image_t scaledImg(gridDimensions().x(), gridDimensions().y());
        boost::gil::resize_view(
            boost::gil::const_view(img)
          , boost::gil::view(scaledImg)
          , boost::gil::bilinear_sampler()
        );

        boost::gil::rgb8_image_t::const_view_t imgView = boost::gil::const_view(scaledImg);
        CoordBox<2> box = ret->boundingBox();
        for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) {
            bool setForce = false;
            FloatCoord<2> force;

            for (std::size_t j = 0; j < shapes.size(); ++j) {
                shapes[j]->initCell(&force, &setForce, *i);
            }

            // force alpha channel to 0xff to ensure all particles are opaque
            boost::gil::rgb8_image_t::value_type pixel = imgView(i->x(), i->y());
            unsigned color = 0xff000000 +
                (pixel[0] << 16) +
                (pixel[1] << 8) +
                (pixel[2] << 0);
            ret->set(*i, Cell(color, *i, setForce, force, rand() % Cell::MAX_SPAWN_COUNTDOWN));
        }
        std::cout << "done ...\n";
    }
Example #4
0
bool DirtyListDescriber::showChanges(QWidget* aParent)
{
    QDialog* dlg = new QDialog(aParent);
    Ui.setupUi(dlg);
    dlg->setWindowFlags(dlg->windowFlags() & ~Qt::WindowContextHelpButtonHint);
    theListWidget = Ui.ChangesList;

    runVisit();

    CoordBox bbox = theDocument->getDirtyOrOriginLayer()->boundingBox();
    QString bboxComment = QString("BBOX:%1,%2,%3,%4")
            .arg(QString::number(bbox.bottomLeft().x(), 'f', 2))
            .arg(QString::number(bbox.bottomLeft().y(), 'f', 2))
            .arg(QString::number(bbox.topRight().x(), 'f', 2))
            .arg(QString::number(bbox.topRight().y(), 'f', 2));

    QString statComment = QString("ADD:%1 UPD:%2 DEL:%3").arg(glbAdded).arg(glbUpdated).arg(glbDeleted);

    glbChangeSetComment = bboxComment + " " + statComment;
    Ui.edChangesetComment->setText(glbChangeSetComment);
    Ui.edChangesetComment->selectAll();

    bool ok = (dlg->exec() == QDialog::Accepted);

    if (!Ui.edChangesetComment->text().isEmpty())
        glbChangeSetComment = Ui.edChangesetComment->text();
    else
        glbChangeSetComment = "-";

    Task = Ui.ChangesList->count();
    SAFE_DELETE(dlg)
    return ok;
}
Example #5
0
 virtual void grid(GridBase<CELL_TYPE, 1> *ret)
 {
     CoordBox<1> boundingBox = ret->boundingBox();
     for (CoordBox<1>::Iterator i = boundingBox.begin(); i != boundingBox.end(); ++i) {
         CELL_TYPE cell(i->x() % width(), i->x() / width());
         ret->set(*i, cell);
     }
 }
Example #6
0
void ScaleInteraction::snapMousePressEvent(QMouseEvent * anEvent, Feature* aLast)
{
    QList<Feature*> sel;
    if (view()->isSelectionLocked()) {
        if (theMain->properties()->selection(0))
            sel.append(theMain->properties()->selection(0));
        else
            sel.append(aLast);
    } else {
        sel = theMain->properties()->selection();
        if (!sel.size() && aLast)
            sel.append(aLast);
    }
    Radius = 1.0;
    clearNoSnap();
    Scaling.clear();
    OriginalPosition.clear();

    if (!sel.size())
        return;

    view()->setInteracting(true);

    StartDragPosition = XY_TO_COORD(anEvent->pos());
    OriginNode = NULL;
    NodeOrigin  = false;
    CoordBox selBB = sel[0]->boundingBox();
    for (int j=0; j<sel.size(); j++) {
        selBB.merge(sel[j]->boundingBox());
        if (CHECK_WAY(sel[j])) {
            Way* R = STATIC_CAST_WAY(sel[j]);
            for (int i=0; i<R->size(); ++i)
                if (std::find(Scaling.begin(),Scaling.end(),R->get(i)) == Scaling.end())
                    Scaling.push_back(R->getNode(i));
            addToNoSnap(R);
        } else if (CHECK_NODE(sel[j])) {
            if (!OriginNode && !NodeOrigin) {
                OriginNode = STATIC_CAST_NODE(sel[j]);
                NodeOrigin = true;
            } else {
                NodeOrigin = false;
            }
        }
    }
    if (Scaling.size() > 1) {
        if (NodeOrigin) {
            ScaleCenter = COORD_TO_XY(OriginNode->position());
        } else {
            ScaleCenter = COORD_TO_XY(selBB.center());
        }
        for (int i=0; i<Scaling.size(); ++i)
        {
            OriginalPosition.push_back(Scaling[i]->position());
            addToNoSnap(Scaling[i]);
        }
    } else
        Scaling.clear();
}
void NativeRenderDialog::setBoundingBox(CoordBox aBBox)
{
    ui.sbMinLat->setValue(aBBox.bottomLeft().y());
    ui.sbMaxLat->setValue(aBBox.topLeft().y());
    ui.sbMinLon->setValue(aBBox.topLeft().x());
    ui.sbMaxLon->setValue(aBBox.topRight().x());

    prtW->updatePreview();
}
Example #8
0
    void stepFinished(const GridType& grid, unsigned step, WriterEvent event)
    {
        avrgTemperature = 0;

        CoordBox<2> box = grid.boundingBox();
        for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) {
            avrgTemperature += grid.get(*i).temperature;
        }

        avrgTemperature /= box.dimensions.prod();
        std::cout << "averageTemperature(" << step << ") = " << avrgTemperature << "\n";
    }
Example #9
0
bool downloadOSM(QWidget* aParent, const QString& aWeb, const QString& aUser, const QString& aPassword, const CoordBox& aBox , Document* theDocument, Layer* theLayer)
{
    if (checkForConflicts(theDocument))
    {
        QMessageBox::warning(aParent,QApplication::translate("Downloader","Unresolved conflicts"), QApplication::translate("Downloader","Please resolve existing conflicts first"));
        return false;
    }
    Downloader Rcv(aUser, aPassword);
    QString URL = Rcv.getURLToMap();
    URL = URL.arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f');

    QUrl theUrl(aWeb+URL);
    return downloadOSM(aParent, theUrl, aUser, aPassword, theDocument, theLayer);
}
Example #10
0
bool downloadTracksFromOSM(QWidget* Main, const QString& aWeb, const QString& aUser, const QString& aPassword, const CoordBox& aBox , Document* theDocument)
{
    Downloader theDownloader(aUser, aPassword);
    QList<TrackLayer*> theTracklayers;
    //TrackMapLayer* trackLayer = new TrackMapLayer(QApplication::translate("Downloader","Downloaded tracks"));
    //theDocument->add(trackLayer);

    IProgressWindow* aProgressWindow = dynamic_cast<IProgressWindow*>(Main);
    if (!aProgressWindow)
        return false;

    QProgressDialog* dlg = aProgressWindow->getProgressDialog();
    dlg->setWindowTitle(QApplication::translate("Downloader","Parsing..."));

    QProgressBar* Bar = aProgressWindow->getProgressBar();
    Bar->setTextVisible(false);
    Bar->setMaximum(11);

    QLabel* Lbl = aProgressWindow->getProgressLabel();
    Lbl->setText(QApplication::translate("Downloader","Parsing XML"));

    if (dlg)
        dlg->show();

    theDownloader.setAnimator(dlg,Lbl,Bar,true);
    for (int Page=0; ;++Page)
    {
        Lbl->setText(QApplication::translate("Downloader","Downloading trackpoints %1-%2").arg(Page*5000+1).arg(Page*5000+5000));
        QString URL = theDownloader.getURLToTrackPoints();
        URL = URL.arg(aBox.bottomLeft().x()).
                arg(aBox.bottomLeft().y()).
                arg(aBox.topRight().x()).
                arg(aBox.topRight().y()).
                arg(Page);
        QUrl theUrl(aWeb+URL);
        if (!theDownloader.go(theUrl))
            return false;
        if (theDownloader.resultCode() != 200)
            return false;
        int Before = theTracklayers.size();
        QByteArray Ar(theDownloader.content());
        bool OK = importGPX(Main, Ar, theDocument, theTracklayers, true);
        if (!OK)
            return false;
        if (Before == theTracklayers.size())
            break;
        theTracklayers[theTracklayers.size()-1]->setName(QApplication::translate("Downloader", "Downloaded track - nodes %1-%2").arg(Page*5000+1).arg(Page*5000+5000));
    }
    return true;
}
Example #11
0
bool DrawingLayer::toXML(QXmlStreamWriter& stream, bool asTemplate, QProgressDialog * progress)
{
    bool OK = true;

    stream.writeStartElement(metaObject()->className());
    Layer::toXML(stream, asTemplate, progress);

    if (!asTemplate) {
        stream.writeStartElement("osm");
        stream.writeAttribute("version", "0.6");
        stream.writeAttribute("generator", QString("%1 %2").arg(STRINGIFY(PRODUCT)).arg(STRINGIFY(VERSION)));

        if (p->Features.size()) {
            stream.writeStartElement("bound");
            CoordBox layBB = boundingBox();
            QString S = QString().number(layBB.bottomLeft().y(),'f',6) + ",";
            S += QString().number(layBB.bottomLeft().x(),'f',6) + ",";
            S += QString().number(layBB.topRight().y(),'f',6) + ",";
            S += QString().number(layBB.topRight().x(),'f',6);
            stream.writeAttribute("box", S);
            stream.writeAttribute("origin", QString("http://www.openstreetmap.org/api/%1").arg(M_PREFS->apiVersion()));
            stream.writeEndElement();
        }

        QList<MapFeaturePtr>::iterator it;
        for(it = p->Features.begin(); it != p->Features.end(); it++)
            (*it)->toXML(stream, progress);
        stream.writeEndElement();

        QList<CoordBox> downloadBoxes = p->theDocument->getDownloadBoxes(this);
        if (downloadBoxes.size() && p->theDocument->getLastDownloadLayerTime().secsTo(QDateTime::currentDateTime()) < 12*3600) { // Do not export downloaded areas if older than 12h
            stream.writeStartElement("DownloadedAreas");
            QListIterator<CoordBox>it(downloadBoxes);
            while(it.hasNext()) {
                it.next().toXML("DownloadedBoundingBox", stream);
            }
            stream.writeEndElement();
        }
    }
    stream.writeEndElement();

    return OK;
}
Example #12
0
    virtual void grid(GridBase<BushFireCell, 2> *ret)
    {
        Random::seed(4711);
        CoordBox<2> box = ret->boundingBox();
        Grid<double> humidityGrid = createUnwarpedPlasmaField(gridDimensions(), 0.5);
        Grid<double> fuelGrid = createUnwarpedPlasmaField(gridDimensions(), 0.01);

        for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) {
            ret->set(*i, BushFireCell(humidityGrid[*i], 1.0 + fuelGrid[*i]));
        }

        CoordBox<2> seatOfFire(Coord<2>(100, 100), Coord<2>(10, 10));

        for (CoordBox<2>::Iterator i = seatOfFire.begin(); i != seatOfFire.end(); ++i) {
            if (box.inBounds(*i)) {
                ret->set(*i, BushFireCell(0, 10.0, 200.0, BushFireCell::BURNING));
            }
        }
    }
Example #13
0
    virtual void grid(GridBase<Cell, 3> *ret)
    {
        CoordBox<3> box = ret->boundingBox();
        Coord<3> offset =
            Coord<3>::diagonal(gridDimensions().x() * 5 / 128);
        int size = gridDimensions().x() * 50 / 128;


        for (int z = 0; z < size; ++z) {
            for (int y = 0; y < size; ++y) {
                for (int x = 0; x < size; ++x) {
                    Coord<3> c = offset + Coord<3>(x, y, z);
                    if (box.inBounds(c)) {
                        ret->set(c, Cell(0.99999999999));
                    }
                }
            }
        }
    }
Example #14
0
    virtual void grid(GridBase<ConwayCell, 2> *ret)
    {
        CoordBox<2> rect = ret->boundingBox();
        std::vector<Coord<2> > startCells;
        // start with a single glider...
        //          x
        //           x
        //         xxx
        startCells +=
            Coord<2>(11, 10),
            Coord<2>(12, 11),
            Coord<2>(10, 12), Coord<2>(11, 12), Coord<2>(12, 12);


        // ...add a Diehard pattern...
        //                x
        //          xx
        //           x   xxx
        startCells +=
            Coord<2>(55, 70), Coord<2>(56, 70), Coord<2>(56, 71),
            Coord<2>(60, 71), Coord<2>(61, 71), Coord<2>(62, 71),
            Coord<2>(61, 69);

        // ...and an Acorn pattern:
        //        x
        //          x
        //       xx  xxx
        startCells +=
            Coord<2>(111, 30),
            Coord<2>(113, 31),
            Coord<2>(110, 32), Coord<2>(111, 32),
            Coord<2>(113, 32), Coord<2>(114, 32), Coord<2>(115, 32);


        for (std::vector<Coord<2> >::iterator i = startCells.begin();
             i != startCells.end();
             ++i) {
            if (rect.inBounds(*i)) {
                ret->set(*i, ConwayCell(true));
            }
        }
    }
Example #15
0
CoordBox Layer::boundingBox()
{
    if(p->Features.size()==0) return CoordBox(Coord(0,0),Coord(0,0));
    CoordBox Box;
    bool haveFirst = false;
    for (int i=0; i<p->Features.size(); ++i) {
        if (p->Features.at(i)->isDeleted())
            continue;
        if (p->Features.at(i)->notEverythingDownloaded())
            continue;
        if (p->Features.at(i)->boundingBox().isNull())
            continue;
        if (haveFirst)
            Box.merge(p->Features.at(i)->boundingBox());
        else {
            Box = p->Features.at(i)->boundingBox();
            haveFirst = true;
        }
    }
    return Box;
}
Example #16
0
bool downloadOSM(QWidget* aParent, const QString& aWeb, const QString& aUser, const QString& aPassword, const CoordBox& aBox , Document* theDocument, Layer* theLayer)
{
    if (checkForConflicts(theDocument))
    {
        QMessageBox::warning(aParent,QApplication::translate("Downloader","Unresolved conflicts"), QApplication::translate("Downloader","Please resolve existing conflicts first"));
        return false;
    }
    Downloader Rcv(aUser, aPassword);
    QString URL = Rcv.getURLToMap();

    if ((fabs(aBox.bottomLeft().x()) < 180.0 && fabs(aBox.topRight().x()) > 180.0) 
     || (fabs(aBox.bottomLeft().x()) > 180.0 && fabs(aBox.topRight().x()) < 180.0)) {
        /* Check for +-180 meridian, and split query in two if necessary */
        int sign = (aBox.bottomLeft().x() > 0) ? 1 : -1;
        CoordBox q1 = aBox, q2 = aBox;
        if (aBox.bottomLeft().x() > 0) {
            q1.setRight(180*sign);
            q2.setLeft(-180*sign);
            q2.setRight(q2.right()-360);
        } else {
            q1.setLeft(180*sign);
            q2.setRight(-180*sign);
            q2.setLeft(q2.left()+360);
        }
        return downloadOSM(aParent, aWeb, aUser, aPassword, q1, theDocument, theLayer)
            && downloadOSM(aParent, aWeb, aUser, aPassword, q2, theDocument, theLayer);

    } else {
        /* Normal code path */
        URL = URL.arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f');
        QUrl theUrl(aWeb+URL);
        return downloadOSM(aParent, theUrl, aUser, aPassword, theDocument, theLayer);
    }
}
Example #17
0
    virtual void grid(GridBase<CircleCell, 2> *ret)
    {
        CoordBox<2> rect = ret->boundingBox();
        std::vector<std::pair<Coord<2>, CircleCell> > seeds(3);
        seeds[0] = std::make_pair(
            Coord<2>(1 * gridDimensions().x() / 4,
                     2 * gridDimensions().y() / 3),
            CircleCell(std::make_pair(0.5, 0.5), 0.2));
        seeds[0] = std::make_pair(
            Coord<2>(3 * gridDimensions().x() / 4,
                     2 * gridDimensions().y() / 3),
            CircleCell(std::make_pair(0.5, 0.5), 0.2));
        seeds[0] = std::make_pair(
            Coord<2>(1 * gridDimensions().x() / 2,
                     1 * gridDimensions().y() / 3),
            CircleCell(std::make_pair(0.5, 0.5), 0.4));

        for (std::vector<std::pair<Coord<2>, CircleCell> >::iterator i =
                 seeds.begin(); i != seeds.end(); ++i) {
            if (rect.inBounds(i->first)) {
                ret->set(i->first, i->second);
            }
        }
    }
Example #18
0
bool downloadMapdust(MainWindow* Main, const CoordBox& aBox, Document* theDocument, SpecialLayer* theLayer)
{
    QUrl url;

    url.setUrl(M_PREFS->getMapdustUrl());

    if (Main)
        Main->view()->setUpdatesEnabled(false);

    Downloader theDownloader("", "");

    SpecialLayer* trackLayer = theLayer;
    if (!trackLayer) {
        trackLayer = new SpecialLayer(QApplication::translate("Downloader","MapDust"), Layer::MapDustLayer);
        trackLayer->setUploadable(false);
        theDocument->add(trackLayer);
    }

    IProgressWindow* aProgressWindow = dynamic_cast<IProgressWindow*>(Main);
    if (!aProgressWindow)
        return false;

    QProgressDialog* dlg = aProgressWindow->getProgressDialog();
    dlg->setWindowTitle(QApplication::translate("Downloader","Parsing..."));

    QProgressBar* Bar = aProgressWindow->getProgressBar();
    Bar->setTextVisible(false);
    Bar->setMaximum(11);

    QLabel* Lbl = aProgressWindow->getProgressLabel();
    Lbl->setText(QApplication::translate("Downloader","Parsing XML"));

    if (dlg)
        dlg->show();

    theDownloader.setAnimator(dlg,Lbl,Bar,true);
    Lbl->setText(QApplication::translate("Downloader","Downloading points"));

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    QUrlQuery theQuery(url);
#define theQuery theQuery
#else
#define theQuery url
#endif
    theQuery.addQueryItem("t", COORD2STRING(aBox.topRight().y()));
    theQuery.addQueryItem("l", COORD2STRING(aBox.bottomLeft().x()));
    theQuery.addQueryItem("b", COORD2STRING(aBox.bottomLeft().y()));
    theQuery.addQueryItem("r", COORD2STRING(aBox.topRight().x()));
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    url.setQuery(theQuery);
#endif
#undef theQuery

    if (!theDownloader.go(url))
        return false;
    if (theDownloader.resultCode() != 200)
        return false;
    QByteArray Ar(theDownloader.content());
    ImportExportGdal gdal(theDocument);
    bool OK = gdal.import(trackLayer, Ar, false);

    if (Main)
        Main->view()->setUpdatesEnabled(true);
    if (OK) {
        if (Main)
            Main->invalidateView();
    }
    return OK;
}
Example #19
0
void MainWindow::showMenu()
{
    ViewMenu* menu = new ViewMenu(this);
    menu->move((width()-menu->width())/2, (height()-menu->height())/2);
    connect(menu, SIGNAL(mapRequested()), SLOT(showMapView()));
    connect(menu, SIGNAL(gpsRequested()), SLOT(showGpsView()));
    menu->exec();
}

void MainWindow::updateGpsPosition(qreal latitude, qreal longitude, QDateTime time, qreal altitude, qreal speed, qreal heading)
{
    Q_UNUSED(heading)
    if (m_gpsview->getGpsDevice()) {
        Coord gpsCoord(longitude,latitude);
        CoordBox vp = m_mapView->viewport();
        qreal lonDiff = vp.lonDiff();
        qreal latDiff = vp.latDiff();
        QRectF vpr = vp.adjusted(lonDiff / 4, -latDiff / 4, -lonDiff / 4, latDiff / 4);
        if (!vpr.contains(gpsCoord)) {
            m_mapView->setCenter(gpsCoord, m_mapView->rect());
            m_mapView->invalidate(true, true);
        }

//        if (ui->gpsRecordAction->isChecked() && !ui->gpsPauseAction->isChecked()) {
//            Node* pt = g_backend.allocNode(gpsRecLayer, gpsCoord);
//            pt->setTime(time);
//            pt->setElevation(altitude);
//            pt->setSpeed(speed);
//            gpsRecLayer->add(pt);
//            curGpsTrackSegment->add(pt);
Example #20
0
bool downloadOSM(MainWindow* Main, const CoordBox& aBox , Document* theDocument)
{
    QString osmWebsite, osmUser, osmPwd;
    static bool DownloadRaw = false;

    QDialog * dlg = new QDialog(Main);

    osmWebsite = M_PREFS->getOsmApiUrl();
    osmUser = M_PREFS->getOsmUser();
    osmPwd = M_PREFS->getOsmPassword();

    Ui::DownloadMapDialog ui;
    ui.setupUi(dlg);
    SlippyMapWidget* SlippyMap = new SlippyMapWidget(ui.groupBox);
#ifndef _MOBILE
    SlippyMap->setMinimumHeight(256);
#endif
    CoordBox Clip(aBox);
    SlippyMap->setViewportArea(Clip);
    ui.verticalLayout->addWidget(SlippyMap);
    QObject::connect(SlippyMap, SIGNAL(redraw()), ui.FromMap, SLOT(toggle()));
    BookmarkListIterator i(*(M_PREFS->getBookmarks()));
    while (i.hasNext()) {
        i.next();
        if (i.value().deleted == false)
            ui.Bookmarks->addItem(i.key());
    }
    ui.edXapiUrl->setText(QString("*[bbox=%1,%2,%3,%4]").arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f'));
    ui.IncludeTracks->setChecked(DownloadRaw);
    ui.ResolveRelations->setChecked(M_PREFS->getResolveRelations());
    bool OK = true, retry = true, directAPI = false;
    QString directUrl;
    while (retry) {
        retry = false;
#ifdef _MOBILE
        dlg->setWindowState(Qt::WindowMaximized);
#endif
        if (dlg->exec() == QDialog::Accepted)
        {
            DownloadRaw = false;
            if (ui.FromBookmark->isChecked())
            {
                Clip = M_PREFS->getBookmarks()->value(ui.Bookmarks->currentText()).Coordinates;
            }
            else if (ui.FromView->isChecked())
            {
                Clip = aBox;
            }
            else if (ui.FromLink->isChecked()) {
                QString link = ui.Link->text();

                if (link.contains("/api/")) {
                    directAPI=true;
                    directUrl = link;
                } else if (link.contains("/browse/")) {
                    QString tag("/browse/");
                    int ix = link.lastIndexOf(tag) + tag.length();
                    directUrl = M_PREFS->getOsmApiUrl();
                    if (!directUrl.endsWith("/")) directUrl += "/";
                    directUrl += link.right(link.length() - ix);
                    if (!directUrl.endsWith("/")) directUrl += "/";
                    directUrl += "full";
                    directAPI=true;
                } else if (link.startsWith("way") || link.startsWith("node") || link.startsWith("relation")) {
                    directUrl = M_PREFS->getOsmApiUrl();
                    if (!directUrl.endsWith("/")) directUrl += "/";
                    directUrl += link;
                    directAPI=true;
                } else {
                    OsmLink ol(link);
                    Clip = ol.getCoordBox();
                    if (Clip.isNull() || Clip.isEmpty())
                        retry = true;
                }
            }
            else if (ui.FromXapi->isChecked())
            {
                directAPI = true;
                directUrl = M_PREFS->getXapiUrl();
                if (!directUrl.endsWith("/")) directUrl += "/";
                directUrl += ui.edXapiUrl->text();
            }
            else if (ui.FromMap->isChecked())
            {
                QRectF R(SlippyMap->viewArea());
                Clip = CoordBox(Coord(R.x(), R.y()), Coord(R.x()+R.width(), R.y()+R.height()));
            }
            if (retry) continue;
            Main->view()->setUpdatesEnabled(false);
            Layer* theLayer = new DrawingLayer(QApplication::translate("Downloader","%1 download").arg(QDateTime::currentDateTime().toString(Qt::ISODate)));
            theDocument->add(theLayer);
            M_PREFS->setResolveRelations(ui.ResolveRelations->isChecked());
            if (directAPI) {
                if (ui.FromXapi->isChecked())
                    theLayer->setUploadable(false);
                OK = downloadOSM(Main,QUrl(QUrl::fromEncoded(directUrl.toLatin1())),osmUser,osmPwd,theDocument,theLayer);
            }
            else
                OK = downloadOSM(Main,osmWebsite,osmUser,osmPwd,Clip,theDocument,theLayer);
            if (OK && ui.IncludeTracks->isChecked())
                OK = downloadTracksFromOSM(Main,osmWebsite,osmUser,osmPwd, Clip,theDocument);
            Main->view()->setUpdatesEnabled(true);
            if (OK)
            {
                theDocument->setLastDownloadLayer(theLayer);
                theDocument->addDownloadBox(theLayer, Clip);
#ifndef _MOBILE
                if (directAPI)
                    Main->on_viewZoomAllAction_triggered();
                else
#endif
                    Main->view()->setViewport(Clip,Main->view()->rect());
                Main->invalidateView();
            } else {
                retry = true;
                theDocument->remove(theLayer);
                SAFE_DELETE(theLayer);
            }
        }
    }
    delete dlg;
    return OK;
}
Example #21
0
bool downloadOpenstreetbugs(MainWindow* Main, const CoordBox& aBox, Document* theDocument, SpecialLayer* theLayer)
{
    QUrl osbUrl;

    osbUrl.setUrl(M_PREFS->getOpenStreetBugsUrl());
    osbUrl.setPath(osbUrl.path() + "getGPX");

    if (Main)
        Main->view()->setUpdatesEnabled(false);

    Downloader theDownloader("", "");

    QList<TrackLayer*> theTracklayers;
    SpecialLayer* trackLayer = theLayer;
    if (!trackLayer) {
        SpecialLayer* trackLayer = new SpecialLayer(QApplication::translate("Downloader","OpenStreetBugs"),Layer::OsmBugsLayer);
        trackLayer->setUploadable(false);
        theDocument->add(trackLayer);
    }
    theTracklayers << trackLayer;

    IProgressWindow* aProgressWindow = dynamic_cast<IProgressWindow*>(Main);
    if (!aProgressWindow)
        return false;

    QProgressDialog* dlg = aProgressWindow->getProgressDialog();
    dlg->setWindowTitle(QApplication::translate("Downloader","Parsing..."));

    QProgressBar* Bar = aProgressWindow->getProgressBar();
    Bar->setTextVisible(false);
    Bar->setMaximum(11);

    QLabel* Lbl = aProgressWindow->getProgressLabel();
    Lbl->setText(QApplication::translate("Downloader","Parsing XML"));

    if (dlg)
        dlg->show();

    theDownloader.setAnimator(dlg,Lbl,Bar,true);
    Lbl->setText(QApplication::translate("Downloader","Downloading points"));

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    QUrlQuery theQuery(osbUrl);
#define theQuery theQuery
#else
#define theQuery osbUrl
#endif
    theQuery.addQueryItem("t", COORD2STRING(aBox.topRight().y()));
    theQuery.addQueryItem("l", COORD2STRING(aBox.bottomLeft().x()));
    theQuery.addQueryItem("b", COORD2STRING(aBox.bottomLeft().y()));
    theQuery.addQueryItem("r", COORD2STRING(aBox.topRight().x()));
    theQuery.addQueryItem("open", "yes");
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    osbUrl.setQuery(theQuery);
#endif
#undef theQuery

    if (!theDownloader.go(osbUrl))
        return false;
    if (theDownloader.resultCode() != 200)
        return false;
    QByteArray Ar(theDownloader.content());
    bool OK = importGPX(Main, Ar, theDocument, theTracklayers, true);

    if (Main)
        Main->view()->setUpdatesEnabled(true);
    if (OK) {
        if (Main)
            Main->invalidateView();
    }
    return OK;
}