|
| 1 | + |
| 2 | +/**Describes the result of a snapping operation*/ |
| 3 | +struct QgsSnappingResult |
| 4 | +{ |
| 5 | +%TypeHeaderCode |
| 6 | +#include <qgssnapper.h> |
| 7 | +%End |
| 8 | + |
| 9 | + /**The coordinates of the snapping result*/ |
| 10 | + QgsPoint snappedVertex; |
| 11 | + /**The vertex index of snappedVertex |
| 12 | + or -1 if no such vertex number (e.g. snap to segment)*/ |
| 13 | + int snappedVertexNr; |
| 14 | + /**The layer coordinates of the vertex before snappedVertex*/ |
| 15 | + QgsPoint beforeVertex; |
| 16 | + /**The index of the vertex before snappedVertex |
| 17 | + or -1 if no such vertex*/ |
| 18 | + int beforeVertexNr; |
| 19 | + /**The layer coordinates of the vertex after snappedVertex*/ |
| 20 | + QgsPoint afterVertex; |
| 21 | + /**The index of the vertex after snappedVertex |
| 22 | + or -1 if no such vertex*/ |
| 23 | + int afterVertexNr; |
| 24 | + /**Index of the snapped geometry*/ |
| 25 | + int snappedAtGeometry; |
| 26 | + /**Layer where the snap occured*/ |
| 27 | + const QgsVectorLayer* layer; |
| 28 | +}; |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +/**A class that allows advanced snapping operations on a set of vector layers*/ |
| 33 | +class QgsSnapper |
| 34 | +{ |
| 35 | +%TypeHeaderCode |
| 36 | +#include <qgssnapper.h> |
| 37 | +%End |
| 38 | + |
| 39 | +public: |
| 40 | + /**Snap to vertex, to segment or both*/ |
| 41 | + enum SNAP_TO |
| 42 | + { |
| 43 | + SNAP_TO_VERTEX, |
| 44 | + SNAP_TO_SEGMENT, |
| 45 | + //snap to vertex and also to segment if no vertex is within the search tolerance |
| 46 | + SNAP_TO_VERTEX_AND_SEGMENT |
| 47 | + }; |
| 48 | + |
| 49 | + enum SNAP_MODE |
| 50 | + { |
| 51 | + /**Only one snapping result is retured*/ |
| 52 | + ONE_RESULT, |
| 53 | + /**Several snapping results which have the same position are returned. This is usefull for topological |
| 54 | + editing*/ |
| 55 | + SEVERAL_RESULTS_SAME_POSITION, |
| 56 | + /**All results within the given layer tolerances are returned*/ |
| 57 | + ALL_RESULTS_WITHIN_GIVEN_TOLERANCES |
| 58 | + }; |
| 59 | + |
| 60 | + QgsSnapper(QgsMapRender* mapRender); |
| 61 | + ~QgsSnapper(); |
| 62 | + /**Does the snapping operation |
| 63 | + @param startPoint the start point for snapping (in pixel coordinates) |
| 64 | + @param snappingResult the list where the results are inserted (everything in map coordinate system) |
| 65 | + @return 0 in case of success*/ |
| 66 | + int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult); |
| 67 | + |
| 68 | + //setters |
| 69 | + void setLayersToSnap(const QList<QgsVectorLayer*>& layerList); |
| 70 | + void setTolerances(const QList<double>& toleranceList); |
| 71 | + // TODO wrap void setSnapToList(const QList<QgsSnapper::SNAP_TO>& snapToList); |
| 72 | + void setSnapMode(QgsSnapper::SNAP_MODE snapMode); |
| 73 | + |
| 74 | +}; |
0 commit comments