2008-01-09 21:54:36 +00:00
/**Describes the result of a snapping operation*/
struct QgsSnappingResult
{
%TypeHeaderCode
#include <qgssnapper.h>
%End
2012-09-24 02:28:15 +02:00
2008-01-09 21:54:36 +00:00
/**The coordinates of the snapping result*/
QgsPoint snappedVertex;
2012-09-24 02:28:15 +02:00
/**The vertex index of snappedVertex
2008-01-09 21:54:36 +00:00
or -1 if no such vertex number (e.g. snap to segment)*/
int snappedVertexNr;
/**The layer coordinates of the vertex before snappedVertex*/
QgsPoint beforeVertex;
/**The index of the vertex before snappedVertex
or -1 if no such vertex*/
int beforeVertexNr;
/**The layer coordinates of the vertex after snappedVertex*/
QgsPoint afterVertex;
/**The index of the vertex after snappedVertex
or -1 if no such vertex*/
int afterVertexNr;
/**Index of the snapped geometry*/
2012-09-24 02:28:15 +02:00
qint64 snappedAtGeometry;
2008-01-09 21:54:36 +00:00
/**Layer where the snap occured*/
const QgsVectorLayer* layer;
};
/**A class that allows advanced snapping operations on a set of vector layers*/
class QgsSnapper
{
%TypeHeaderCode
#include <qgssnapper.h>
%End
2012-09-24 02:28:15 +02:00
public:
/**Snap to vertex, to segment or both*/
enum SnappingType
2008-01-09 21:54:36 +00:00
{
2008-10-24 23:22:44 +00:00
SnapToVertex,
SnapToSegment,
2008-01-09 21:54:36 +00:00
//snap to vertex and also to segment if no vertex is within the search tolerance
2008-10-24 23:22:44 +00:00
SnapToVertexAndSegment
2008-01-09 21:54:36 +00:00
};
2012-09-24 02:28:15 +02:00
enum SnappingMode
2008-01-09 21:54:36 +00:00
{
/**Only one snapping result is retured*/
2008-10-24 23:22:44 +00:00
SnapWithOneResult,
2012-09-24 02:28:15 +02:00
/**Several snapping results which have the same position are returned.
This is useful for topological editing*/
2008-10-24 23:22:44 +00:00
SnapWithResultsForSamePosition,
2008-01-09 21:54:36 +00:00
/**All results within the given layer tolerances are returned*/
2008-10-24 23:22:44 +00:00
SnapWithResultsWithinTolerances
2008-01-09 21:54:36 +00:00
};
2008-11-17 17:20:21 +00:00
struct SnapLayer
{
/**The layer to which snapping is applied*/
QgsVectorLayer* mLayer;
/**The snapping tolerances for the layers, always in source coordinate systems of the layer*/
double mTolerance;
/**What snapping type to use (snap to segment or to vertex)*/
QgsSnapper::SnappingType mSnapTo;
2009-04-05 16:46:13 +00:00
/**What unit is used for tolerance*/
QgsTolerance::UnitType mUnitType;
2012-09-24 02:28:15 +02:00
};
2008-01-09 21:54:36 +00:00
2012-09-24 02:28:15 +02:00
QgsSnapper( QgsMapRenderer* mapRender );
~QgsSnapper();
/**Does the snapping operation
@param startPoint the start point for snapping (in pixel coordinates)
@param snappingResult the list where the results are inserted (everything in map coordinate system)
@param excludePoints a list with (map coordinate) points that should be excluded in the snapping result. Useful e.g. for vertex moves where a vertex should not be snapped to its original position
@return 0 in case of success*/
2012-09-26 17:56:27 +02:00
int snapPoint( const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult /Out/, const QList<QgsPoint>& excludePoints = QList<QgsPoint>() );
2008-01-09 21:54:36 +00:00
2012-09-24 02:28:15 +02:00
//setters
void setSnapLayers( const QList<QgsSnapper::SnapLayer>& snapLayers );
void setSnapMode( QgsSnapper::SnappingMode snapMode );
2012-09-26 17:56:27 +02:00
};