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(); }
// export bool ImportExportGdal::export_(const QList<Feature *>& featList) { const char *pszDriverName = "SQLite"; OGRSFDriver *poDriver; OGRRegisterAll(); poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName); if( poDriver == NULL ) { qDebug( "%s driver not available.", pszDriverName ); return false; } OGRDataSource *poDS; QFile::remove(QString(HOMEDIR + "/test.sqlite")); poDS = poDriver->CreateDataSource( QString(HOMEDIR + "/test.sqlite").toUtf8().constData(), NULL ); if( poDS == NULL ) { qDebug( "Creation of output file failed." ); return false; } poDS->ExecuteSQL("PRAGMA synchronous = OFF", NULL, NULL); OGRSpatialReference *poSRS; poSRS = new OGRSpatialReference(); poSRS->importFromEPSG(4326); char **papszOptions = NULL; papszOptions = CSLSetNameValue( papszOptions, "SPATIALITE", "YES" ); papszOptions = CSLSetNameValue( papszOptions, "FORMAT", "SPATIALITE" ); papszOptions = CSLSetNameValue( papszOptions, "SPATIAL_INDEX", "YES" ); OGRLayer *poLayer; poLayer = poDS->CreateLayer( "osm", poSRS, wkbUnknown, papszOptions); CSLDestroy( papszOptions ); if( poLayer == NULL ) { qDebug( "Layer creation failed." ); return false; } OGRFieldDefn oField("osm_id", OFTReal); if( poLayer->CreateField( &oField ) != OGRERR_NONE ) { qDebug( "Creating field failed." ); return false; } oField.Set("osm_version", OFTInteger ); poLayer->CreateField( &oField ); oField.Set("osm_timestamp", OFTInteger ); poLayer->CreateField( &oField ); OGRFeature *poFeature; foreach (Feature* F, featList) { poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() ); poFeature->SetField( "osm_id", (qreal)(F->id().numId)); #ifndef FRISIUS_BUILD poFeature->SetField( "osm_version", F->versionNumber()); poFeature->SetField( "osm_timestamp", (int)F->time().toTime_t()); #endif if (CHECK_NODE(F)) { Node* N = STATIC_CAST_NODE(F); OGRPoint pt; pt.setX(N->position().x()); pt.setY(N->position().y()); poFeature->SetGeometry( &pt ); } else if (CHECK_WAY(F)) { Way* W = STATIC_CAST_WAY(F); OGRLineString ls; ls.setNumPoints(W->size()); for (int i=0; i<W->size(); ++i) { ls.setPoint(i, W->getNode(i)->position().x(), W->getNode(i)->position().y(), 0); } poFeature->SetGeometry( &ls ); } if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE ) { qDebug( "Failed to create feature in output." ); return false; } OGRFeature::DestroyFeature( poFeature ); }
void MapRenderer::render( QPainter* P, const QMap<RenderPriority, QSet <Feature*> >& theFeatures, const QRectF& pViewport, const QRect& screen, const qreal pixelPerM, const RendererOptions& options ) { theViewport = pViewport; theScreen = screen; thePixelPerM = pixelPerM; qreal Aspect = (double)screen.width() / screen.height(); qreal pAspect = fabs(pViewport.width() / pViewport.height()); qreal wv, hv; if (pAspect > Aspect) { wv = fabs(pViewport.width()); hv = fabs(pViewport.height() * pAspect / Aspect); } else { wv = fabs(pViewport.width() * Aspect / pAspect); hv = fabs(pViewport.height()); } qreal ScaleLon = screen.width() / wv; qreal ScaleLat = screen.height() / hv; theTransform.reset(); theTransform.scale(ScaleLon, -ScaleLat); theTransform.translate(-pViewport.topLeft().x(), -pViewport.topLeft().y()); theOptions = options; theGlobalPainter = M_STYLE->getGlobalPainter(); if (theGlobalPainter.DrawNodes) { NodeWidth = thePixelPerM*theGlobalPainter.NodesProportional+theGlobalPainter.NodesFixed; } else { NodeWidth = thePixelPerM * M_PREFS->getNodeSize(); if (NodeWidth > M_PREFS->getNodeSize()) NodeWidth = M_PREFS->getNodeSize(); } bool bgLayerVisible = TEST_RFLAGS(RendererOptions::BackgroundVisible); bool fgLayerVisible = TEST_RFLAGS(RendererOptions::ForegroundVisible); bool tchpLayerVisible = TEST_RFLAGS(RendererOptions::TouchupVisible); bool lblLayerVisible = TEST_RFLAGS(RendererOptions::NamesVisible); QMap<RenderPriority, QSet<Feature*> >::const_iterator itm; QMap<RenderPriority, QSet<Feature*> >::const_iterator itmCur; QSet<Feature*>::const_iterator it; thePainter = P; thePainter->save(); thePainter->translate(screen.left(), screen.top()); itm = theFeatures.constBegin(); while (itm != theFeatures.constEnd()) { int curLayer = (itm.key()).layer(); itmCur = itm; while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { if (bgLayerVisible) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(thePixelPerM)) continue; bglayer.draw(R); } else if (CHECK_NODE(*it)) bglayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) bglayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } ++itm; } itm = itmCur; while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { if (fgLayerVisible) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(thePixelPerM)) continue; fglayer.draw(R); } else if (CHECK_NODE(*it)) fglayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) fglayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } ++itm; } } if (tchpLayerVisible) { for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(thePixelPerM)) continue; tchuplayer.draw(R); } else if (CHECK_NODE(*it)) tchuplayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) tchuplayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } } if (lblLayerVisible) { for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { P->save(); qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; P->setOpacity(alpha); if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(thePixelPerM)) continue; lbllayer.draw(R); } else if (CHECK_NODE(*it)) lbllayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) lbllayer.draw(STATIC_CAST_RELATION(*it)); P->restore(); } } } thePainter->restore(); }
void MapRenderer::render( QPainter* P, const QMap<RenderPriority, QSet <Feature*> >& theFeatures, const RendererOptions& options, MapView* aView ) { // #ifndef NDEBUG // QTime Start(QTime::currentTime()); // #endif theView = aView; theOptions = options; theGlobalPainter = M_STYLE->getGlobalPainter(); bool bgLayerVisible = TEST_RFLAGS(RendererOptions::BackgroundVisible); bool fgLayerVisible = TEST_RFLAGS(RendererOptions::ForegroundVisible); bool tchpLayerVisible = TEST_RFLAGS(RendererOptions::TouchupVisible); bool lblLayerVisible = TEST_RFLAGS(RendererOptions::NamesVisible); QMap<RenderPriority, QSet<Feature*> >::const_iterator itm; QMap<RenderPriority, QSet<Feature*> >::const_iterator itmCur; QSet<Feature*>::const_iterator it; thePainter = P; itm = theFeatures.constBegin(); while (itm != theFeatures.constEnd()) { int curLayer = (itm.key()).layer(); itmCur = itm; while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { if (bgLayerVisible) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(theView->pixelPerM())) continue; bglayer.draw(R); } else if (CHECK_NODE(*it)) bglayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) bglayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } ++itm; } itm = itmCur; while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { if (fgLayerVisible) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(theView->pixelPerM())) continue; fglayer.draw(R); } else if (CHECK_NODE(*it)) fglayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) fglayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } ++itm; } } if (tchpLayerVisible) { for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(theView->pixelPerM())) continue; tchuplayer.draw(R); } else if (CHECK_NODE(*it)) tchuplayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) tchuplayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } } for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin() ;it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) P->setOpacity(alpha); (*it)->draw(*P, aView); } } if (lblLayerVisible) { for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { P->save(); qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; P->setOpacity(alpha); if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(theView->pixelPerM())) continue; lbllayer.draw(R); } else if (CHECK_NODE(*it)) lbllayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) lbllayer.draw(STATIC_CAST_RELATION(*it)); P->restore(); } } } // #ifndef NDEBUG // QTime Stop(QTime::currentTime()); // qDebug() << Start.msecsTo(Stop) << "ms"; // #endif }