Skip to content
Permalink
Browse files
projection support
git-svn-id: http://svn.osgeo.org/qgis/trunk@5411 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed May 3, 2006
1 parent 0910ad4 commit ab56c02fd6c4874d33629934780ca92ffd8571c3
Showing with 86 additions and 14 deletions.
  1. +65 −11 src/plugins/grass/qgsgrassedit.cpp
  2. +16 −0 src/plugins/grass/qgsgrassedit.h
  3. +5 −3 src/plugins/grass/qgsgrassedittools.cpp
@@ -55,6 +55,7 @@
#include "qgslegend.h"
#include "qgsvertexmarker.h"
#include "qgsrubberband.h"
#include "qgsproject.h"

extern "C" {
#include <grass/gis.h>
@@ -120,6 +121,8 @@ QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
mIface = iface;
mNewMap = false;

mProjectionEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);

mCanvas = mIface->getMapCanvas();

// TODO QGIS: crash if canvas is empty
@@ -130,10 +133,10 @@ QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
if ( !isEditable(layer) ) return;

//TODO dynamic_cast ?
QgsVectorLayer *vector = (QgsVectorLayer*)layer;
mLayer = (QgsVectorLayer*)layer;

//TODO dynamic_cast ?
mProvider = (QgsGrassProvider *) vector->getDataProvider();
mProvider = (QgsGrassProvider *) mLayer->getDataProvider();

init();

@@ -1097,11 +1100,20 @@ double QgsGrassEdit::threshold ( void )
int snapPixels = mSnapPixels->text().toInt();

// Convert to map units (not nice)
mTransform = mCanvas->getCoordinateTransform();
double x1 = mTransform->toMapCoordinates( 0, 0 ).x();
double x2 = mTransform->toMapCoordinates( snapPixels, 0 ).x();
QgsPoint p1, p2;
p1 = mTransform->toMapCoordinates(0, 0 );
p2 = mTransform->toMapCoordinates(snapPixels, 0);

return ( x2 - x1 );
if ( mProjectionEnabled )
{
p1 = mLayer->coordinateTransform()->transform(p1, QgsCoordinateTransform::INVERSE );
p2 = mLayer->coordinateTransform()->transform(p2, QgsCoordinateTransform::INVERSE );
}

double dx = p2.x() - p1.x();
double dy = p2.y() - p1.y();
double thresh = sqrt ( dx*dx + dy*dy );
return thresh;
}

void QgsGrassEdit::snap ( double *x, double *y )
@@ -1461,6 +1473,7 @@ void QgsGrassEdit::displayUpdated (void)
#endif

mTransform = mCanvas->getCoordinateTransform();
mProjectionEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);

QPainter *painter = new QPainter();
painter->begin(mPixmap);
@@ -1518,7 +1531,7 @@ void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPaint
for ( int i = 0; i < mPoints->n_points; i++ ) {
point.setX(mPoints->x[i]);
point.setY(mPoints->y[i]);
mTransform->transform(&point);
point = transformLayerToCanvas ( point );
pointArray.setPoint( i, static_cast<int>(round(point.x())),
static_cast<int>(round(point.y())) );
}
@@ -1586,7 +1599,10 @@ void QgsGrassEdit::displayDynamic ( struct line_pnts *Points, double x, double y
#endif
QgsPoint point;

mTransform = mCanvas->getCoordinateTransform();
//mTransform = mCanvas->getCoordinateTransform();

// Dynamic points are in layer coordinate system, we have to
// reproject them to current coordinate system if necessary

mRubberBandLine->reset();

@@ -1596,13 +1612,15 @@ void QgsGrassEdit::displayDynamic ( struct line_pnts *Points, double x, double y
{
point.setX(Points->x[i]);
point.setY(Points->y[i]);
mRubberBandLine->addPoint(point);
point = transformLayerToMap ( point );
mRubberBandLine->addPoint(point);
}
}

mRubberBandIcon->setIconType(type);
mRubberBandIcon->setIconSize(size);
mRubberBandIcon->setCenter(QgsPoint(x,y));
point = transformLayerToMap (QgsPoint(x,y) );
mRubberBandIcon->setCenter(point);
}

void QgsGrassEdit::displayNode ( int node, const QPen & pen, int size, QPainter *painter )
@@ -1620,6 +1638,41 @@ void QgsGrassEdit::displayNode ( int node, const QPen & pen, int size, QPainter
displayIcon ( x, y, pen, QgsVertexMarker::ICON_X, size, painter );
}

QgsPoint QgsGrassEdit::transformLayerToCanvas ( QgsPoint point)
{
if ( mProjectionEnabled && mLayer->coordinateTransform() )
{
try
{
point = mLayer->coordinateTransform()->transform(point);
}
catch(QgsCsException &cse)
{
std::cout << "cannot transform point" << std::endl;
}

}
mTransform->transform(&point);
return point;
}

QgsPoint QgsGrassEdit::transformLayerToMap ( QgsPoint point)
{
if ( mProjectionEnabled && mLayer->coordinateTransform() )
{
try
{
point = mLayer->coordinateTransform()->transform(point);
}
catch(QgsCsException &cse)
{
std::cout << "cannot transform point" << std::endl;
}

}
return point;
}

void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,
int type, int size, QPainter *painter )
{
@@ -1632,7 +1685,8 @@ void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,

point.setX(x);
point.setY(y);
mTransform->transform(&point);

point = transformLayerToCanvas ( point );

int px = static_cast<int>(round(point.x()));
int py = static_cast<int>(round(point.y()));
@@ -37,6 +37,7 @@ class QCloseEvent;
#include "qgsmaptopixel.h"
class QgsRubberBand;
class QgsVertexMarker;
class QgsVectorLayer;
class QgsGrassEditLayer;
class QgsGrassAttributes;

@@ -151,6 +152,9 @@ class QgsGrassEdit: public QMainWindow, private Ui::QgsGrassEditBase
//! Check orphan database records
void checkOrphan ( int field, int cat );

//! pointer to layer
QgsVectorLayer *layer() { return mLayer; }

public slots:
// TODO: once available in QGIS, use only one reciver for all signals

@@ -219,10 +223,19 @@ public slots:
private:
//! Editing is already running
static bool mRunning;

//! Pointer to edited layer
QgsVectorLayer *mLayer;

//! Point / node size (later make editable array of Sizes)
int mSize;

//! Transform from layer coordinates to canvas including reprojection
QgsPoint transformLayerToCanvas ( QgsPoint point);

//! Transform from layer coordinates to current projection
QgsPoint transformLayerToMap ( QgsPoint point);

//! Display all lines and nodes
void displayMap ();

@@ -416,6 +429,9 @@ public slots:
QAction *mEditAttributesAction;
QAction *mCloseEditAction;

// Is projection enabled?
bool mProjectionEnabled;

// Canvas items
QgsRubberBand *mRubberBandLine;
QgsVertexMarker *mRubberBandIcon;
@@ -15,6 +15,8 @@
***************************************************************************/

#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include "qgsgrassedittools.h"
#include "qgsgrassedit.h"
#include "qgsgrassattributes.h"
@@ -35,7 +37,7 @@ QgsGrassEditTool::QgsGrassEditTool(QgsGrassEdit* edit)

void QgsGrassEditTool::canvasPressEvent(QMouseEvent * event)
{
QgsPoint point = toMapCoords(event->pos());
QgsPoint point = toLayerCoords(e->layer(), event->pos());
mouseClick(point, event->button());

// Set last click
@@ -50,7 +52,7 @@ void QgsGrassEditTool::canvasPressEvent(QMouseEvent * event)

void QgsGrassEditTool::canvasMoveEvent(QMouseEvent * event)
{
QgsPoint point = toMapCoords(event->pos());
QgsPoint point = toLayerCoords(e->layer(), event->pos());
mouseMove(point);

e->statusBar()->message(e->mCanvasPrompt);
@@ -634,7 +636,7 @@ void QgsGrassEditDeleteLine::mouseClick(QgsPoint & point, Qt::ButtonState button

if ( e->mSelectedLine == 0 )
e->mSelectedLine = e->mProvider->findLine ( point.x(), point.y(), GV_LINE|GV_BOUNDARY, thresh );

if ( e->mSelectedLine ) { // highlite, propmt
e->displayElement ( e->mSelectedLine, e->mSymb[QgsGrassEdit::SYMB_HIGHLIGHT], e->mSize );
e->setCanvasPropmt( QObject::tr("Delete selected / select next"), "", QObject::tr("Release selected") );

0 comments on commit ab56c02

Please sign in to comment.