From 3264ac5289476a6c85ce97c4c7d97c08b313438e Mon Sep 17 00:00:00 2001 From: wonder Date: Wed, 9 Jan 2008 21:54:36 +0000 Subject: [PATCH] Fixes compilation of bindings, added wrapper for QgsSnapper. git-svn-id: http://svn.osgeo.org/qgis/trunk@7893 c8812cc2-4d05-0410-92ff-de0c093fc19c --- python/core/core.sip | 1 + python/core/qgsgeometry.sip | 2 +- python/core/qgssnapper.sip | 74 ++++++++++++++++++++++++++++++++++ python/core/qgsvectorlayer.sip | 5 ++- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 python/core/qgssnapper.sip diff --git a/python/core/core.sip b/python/core/core.sip index 0473bc09947..e2a56f228ab 100644 --- a/python/core/core.sip +++ b/python/core/core.sip @@ -42,6 +42,7 @@ %Include qgsrenderer.sip %Include qgsscalecalculator.sip %Include qgssinglesymbolrenderer.sip +%Include qgssnapper.sip %Include qgsspatialindex.sip %Include qgsspatialrefsys.sip %Include qgssymbol.sip diff --git a/python/core/qgsgeometry.sip b/python/core/qgsgeometry.sip index 592e9512e16..0b08e67490a 100644 --- a/python/core/qgsgeometry.sip +++ b/python/core/qgsgeometry.sip @@ -301,7 +301,7 @@ class QgsGeometry /** Returns the squared cartesian distance between the given point to the given vertex index*/ - double sqrDistToVertexAt(QgsPoint& point /In, int atVertex); + double sqrDistToVertexAt(QgsPoint& point /In/, int atVertex); /** diff --git a/python/core/qgssnapper.sip b/python/core/qgssnapper.sip new file mode 100644 index 00000000000..721458c5ac6 --- /dev/null +++ b/python/core/qgssnapper.sip @@ -0,0 +1,74 @@ + +/**Describes the result of a snapping operation*/ +struct QgsSnappingResult +{ +%TypeHeaderCode +#include +%End + + /**The coordinates of the snapping result*/ + QgsPoint snappedVertex; + /**The vertex index of snappedVertex + 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*/ + int snappedAtGeometry; + /**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 +%End + +public: + /**Snap to vertex, to segment or both*/ + enum SNAP_TO + { + SNAP_TO_VERTEX, + SNAP_TO_SEGMENT, + //snap to vertex and also to segment if no vertex is within the search tolerance + SNAP_TO_VERTEX_AND_SEGMENT + }; + + enum SNAP_MODE + { + /**Only one snapping result is retured*/ + ONE_RESULT, + /**Several snapping results which have the same position are returned. This is usefull for topological + editing*/ + SEVERAL_RESULTS_SAME_POSITION, + /**All results within the given layer tolerances are returned*/ + ALL_RESULTS_WITHIN_GIVEN_TOLERANCES + }; + + QgsSnapper(QgsMapRender* 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) + @return 0 in case of success*/ + int snapPoint(const QPoint& startPoint, QList& snappingResult); + + //setters + void setLayersToSnap(const QList& layerList); + void setTolerances(const QList& toleranceList); + // TODO wrap void setSnapToList(const QList& snapToList); + void setSnapMode(QgsSnapper::SNAP_MODE snapMode); + +}; diff --git a/python/core/qgsvectorlayer.sip b/python/core/qgsvectorlayer.sip index e82176f76d8..25db2d1e01d 100644 --- a/python/core/qgsvectorlayer.sip +++ b/python/core/qgsvectorlayer.sip @@ -245,8 +245,9 @@ existing rings, 5 no feature found where ring can be inserted*/ @param snap_to to segment / to vertex @return 0 in case of success */ - int snapWithContext(const QgsPoint& startPoint, double snappingTolerance, QMultiMap& snappingResults, \ - QgsSnapper::SNAP_TO snap_to); + // TODO: wrap QMultiMap + //int snapWithContext(const QgsPoint& startPoint, double snappingTolerance, QMultiMap& snappingResults, + // QgsSnapper::SNAP_TO snap_to); /** Commits edited attributes. Depending on the feature id,