Skip to content
Permalink
Browse files
editing: show during mouse move where the point will be snapped to (b…
…y the expense of some performance)

git-svn-id: http://svn.osgeo.org/qgis/trunk@5417 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 4, 2006
1 parent ef53c2f commit b22acec59b3596ea6d11ced6ed15704406aed47a
Showing with 72 additions and 27 deletions.
  1. +22 −16 src/core/qgsgeometry.cpp
  2. +7 −5 src/gui/qgsmaptoolcapture.cpp
  3. +38 −6 src/gui/qgsmaptoolvertexedit.cpp
  4. +5 −0 src/gui/qgsmaptoolvertexedit.h
@@ -313,30 +313,31 @@ QgsPoint QgsGeometry::closestVertex(const QgsPoint& point, QgsGeometryVertexInde
{
unsigned char* ptr=mGeometry+5;
int* nlines=(int*)ptr;
int* npoints;
int* npoints = 0;
ptr+=sizeof(int);
for(int index=0;index<*nlines;++index)
{
npoints=(int*)ptr;
ptr+=sizeof(int);
for(int index2=0;index2<*npoints;++index2)
ptr += (sizeof(int) + 1);
npoints=(int*)ptr;
ptr+=sizeof(int);
for(int index2=0;index2<*npoints;++index2)
{
tempx=(double*)ptr;
ptr+=sizeof(double);
tempy=(double*)ptr;
if(point.sqrDist(*tempx,*tempy)<actdist)
tempx=(double*)ptr;
ptr+=sizeof(double);
tempy=(double*)ptr;
ptr+=sizeof(double);
if(point.sqrDist(*tempx,*tempy)<actdist)
{
x=*tempx;
y=*tempy;
actdist=point.sqrDist(*tempx,*tempy);
vertexnr = vertexcounter;
x=*tempx;
y=*tempy;
actdist=point.sqrDist(*tempx,*tempy);
vertexnr = vertexcounter;
}
ptr+=sizeof(double);
++vertexcounter;
++vertexcounter;
}
}
}
break;
break;

case QGis::WKBMultiPolygon:
{
@@ -482,6 +483,7 @@ bool QgsGeometry::moveVertexAt(double x, double y, QgsGeometryVertexIndex atVert
int pointindex = 0;
for(int linenr = 0; linenr < *nrLines; ++linenr)
{
ptr += sizeof(int) + 1;
nrPoints = (int*)ptr;
ptr += sizeof(int);
if(vertexnr >= pointindex && vertexnr < pointindex + (*nrPoints))
@@ -840,7 +842,6 @@ bool QgsGeometry::insertVertexBefore(double x, double y, QgsGeometryVertexIndex
{
case QGis::WKBPoint://cannot insert a vertex before another one on point types
case QGis::WKBMultiPoint:
break;
case QGis::WKBLineString:
{
int* nPoints = (int*)ptr;
@@ -871,6 +872,9 @@ bool QgsGeometry::insertVertexBefore(double x, double y, QgsGeometryVertexIndex
break;
}
case QGis::WKBMultiLineString:
{
break;
}
case QGis::WKBPolygon:
{
int* nRings = (int*)ptr;
@@ -1092,6 +1096,7 @@ bool QgsGeometry::vertexAt(double &x, double &y,
ptr += sizeof(int);
for(int linenr = 0; linenr < *nLines; ++linenr)
{
ptr += sizeof(int) + 1;
nPoints = (int*)ptr;
ptr += sizeof(int);
for(int pointnr = 0; pointnr < *nPoints; ++pointnr)
@@ -1271,6 +1276,7 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
int pointindex = 0;//global pointindex
for(int linenr = 0; linenr < *nLines; ++linenr)
{
ptr += sizeof(int) + 1;
nPoints = (int*)ptr;
ptr += sizeof(int);
prevx = 0;
@@ -108,11 +108,10 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e)
if(vlayer->getDataProvider()->capabilities()&QgsVectorDataProvider::AddFeatures)
{
QgsFeature* f = new QgsFeature(0,"WKBPoint");

QgsPoint savePoint = maybeInversePoint(idPoint, "adding point");
// snap point to points within the vector layer snapping tolerance
vlayer->snapPoint(idPoint, tolerance);
// project to layer's SRS
QgsPoint savePoint = maybeInversePoint(idPoint, "adding point");
vlayer->snapPoint(savePoint, tolerance);

// create geos geometry and attach it to feature
int size=5+2*sizeof(double);
@@ -162,7 +161,6 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e)
QgsPoint digitisedPoint = toMapCoords(e->pos());
vlayer->snapPoint(digitisedPoint, tolerance);
mCaptureList.push_back(digitisedPoint);

mRubberBand->addPoint(digitisedPoint);

if (e->button() == Qt::LeftButton)
@@ -272,7 +270,11 @@ void QgsMapToolCapture::canvasMoveEvent(QMouseEvent * e)
if (mCapturing)
{
// show the rubber-band from the last click
mRubberBand->movePoint(toMapCoords(e->pos()));
QgsVectorLayer *vlayer = dynamic_cast <QgsVectorLayer*>(mCanvas->currentLayer());
double tolerance = QgsProject::instance()->readDoubleEntry("Digitizing","/Tolerance",0);
QgsPoint rbpoint = toMapCoords(e->pos());
vlayer->snapPoint(rbpoint, tolerance); //show snapping during dragging
mRubberBand->movePoint(rbpoint);
}

} // mouseMoveEvent
@@ -47,13 +47,19 @@ void QgsMapToolVertexEdit::canvasMoveEvent(QMouseEvent * e)
{
if (e->buttons() == Qt::LeftButton && (mTool == AddVertex || mTool == MoveVertex))
{

#ifdef QGISDEBUG
qWarning("Moving rubber band for moveVertex");
#endif

int index = (mStartPointValid ? 1 : 0);
mRubberBand->movePoint(index, toMapCoords(e->pos()));
//snap to nearest vertex of vectorlayer
QgsPoint rbpoint = toMapCoords(e->pos());
if(mTool == AddVertex)
{
snapVertex(rbpoint, mSnappedAtFeatureId, mSnappedBeforeVertex.back());
mRubberBand->movePoint(index, rbpoint);
}
else if(mTool == MoveVertex)
{
snapVertex(rbpoint, mSnappedAtFeatureId, mSnappedAtVertex.back());
mRubberBand->movePoint(index, rbpoint);
}
}

}
@@ -304,6 +310,7 @@ void QgsMapToolVertexEdit::canvasReleaseEvent(QMouseEvent * e)

//snap to nearest vertex of vectorlayer
snapVertex(point, mSnappedAtFeatureId, mSnappedBeforeVertex.back());

#ifdef QGISDEBUG
std::cout << "QgsMapToolVertexEdit::canvasReleaseEvent: AddVertex." << std::endl;
#endif
@@ -360,3 +367,28 @@ void QgsMapToolVertexEdit::deactivate()
mRubberBand = 0;
}

QgsPoint QgsMapToolVertexEdit::maybeInversePoint(QgsPoint point, const char whenmsg[])
{
QgsVectorLayer *vlayer = dynamic_cast <QgsVectorLayer*>(mCanvas->currentLayer());
QgsPoint transformedPoint;

if( mCanvas->projectionsEnabled() )
{
// Do reverse transformation before saving. If possible!
try
{
transformedPoint = vlayer->coordinateTransform()->transform(point, QgsCoordinateTransform::INVERSE);
}
catch(QgsCsException &cse)
{
//#ifdef QGISDEBUG
std::cout << "Caught transform error when " << whenmsg <<"."
<< "Setting untransformed values." << std::endl;
//#endif
// Transformation failed,. Bail out with original rectangle.
return point;
}
return transformedPoint;
}
return point;
}
@@ -57,6 +57,11 @@ class QgsMapToolVertexEdit : public QgsMapTool

//! returns tolerance in map coordinates
double tolerance();

/** Helper function to inverse project a point if projections
are enabled. Failsafe, returns the sent point if anything fails.
@whenmsg is a part fo the error message. */
QgsPoint maybeInversePoint(QgsPoint point, const char whenmsg[]);

//! current vertex edit tool
enum Tool mTool;

0 comments on commit b22acec

Please sign in to comment.