Skip to content
Permalink
Browse files
snap to first point of new line
git-svn-id: http://svn.osgeo.org/qgis/trunk@5437 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed May 11, 2006
1 parent 52625f7 commit 65fc91a912bd885590a5e3d6ead060648b24be36
Showing with 58 additions and 1 deletion.
  1. +43 −0 src/plugins/grass/qgsgrassedit.cpp
  2. +2 −0 src/plugins/grass/qgsgrassedit.h
  3. +13 −1 src/plugins/grass/qgsgrassedittools.cpp
@@ -1140,6 +1140,49 @@ void QgsGrassEdit::snap ( QgsPoint & point )
point.setY(y);
}

void QgsGrassEdit::snap ( QgsPoint & point, double startX, double startY )
{
double x = point.x();
double y = point.y();

double thresh = threshold();

// Start
double startDist = hypot ( x-startX, y-startY);
bool startIn = false;
if ( startDist <= thresh ) startIn = true;

// Nearest node
double nodeX, nodeY;
double nodeDist;
bool nodeIn = false;
int node = mProvider->findNode ( x, y, thresh );

if ( node > 0 )
{
mProvider->nodeCoor ( node, &nodeX, &nodeY );
nodeDist = hypot ( x-nodeX, y-nodeY);
nodeIn = true;
}
std::cerr << "startIn = " << startIn << std::endl;
std::cerr << "nodeIn = " << nodeIn << std::endl;
std::cerr << "startDist = " << startDist << std::endl;
std::cerr << "nodeDist = " << nodeDist << std::endl;

// Choose
if ( (startIn && !nodeIn) || (startIn && nodeIn && startDist < nodeDist) )
{
x = startX; y = startY;
}
else if ( (!startIn && nodeIn) || (startIn && nodeIn && startDist > nodeDist) )
{
x = nodeX; y = nodeY;
}

point.setX(x);
point.setY(y);
}

void QgsGrassEdit::newPoint(void) { startTool(QgsGrassEdit::NEW_POINT); }
void QgsGrassEdit::newLine(void) {
std::cerr << "QgsGrassEdit::newLine" << std::endl;
@@ -395,6 +395,8 @@ public slots:
/** Snap to nearest node in current threshold */
void snap ( QgsPoint & point );
void snap ( double *x, double *y);
/** Snap point line considering line starting point */
void snap ( QgsPoint & point, double startX, double startY);

/** Attributes */
QgsGrassAttributes *mAttributes;
@@ -151,8 +151,20 @@ void QgsGrassEditNewLine::mouseClick(QgsPoint & point, Qt::ButtonState button)
{
switch ( button ) {
case Qt::LeftButton:
e->snap ( point );
if ( e->mEditPoints->n_points > 2 )
{
e->snap ( point, e->mEditPoints->x[0], e->mEditPoints->y[0] );
}
else
{
e->snap ( point );
}
Vect_append_point ( e->mEditPoints, point.x(), point.y(), 0.0 );

// Draw
Vect_reset_line ( e->mPoints );
Vect_append_points ( e->mPoints, e->mEditPoints, GV_FORWARD );
e->displayDynamic ( e->mPoints );
break;
case Qt::MidButton:
if ( e->mEditPoints->n_points > 0 ) {

0 comments on commit 65fc91a

Please sign in to comment.