00001 /*************************************************************************** 00002 qgssnapper.h 00003 ------------ 00004 begin : June 7, 2007 00005 copyright : (C) 2007 by Marco Hugentobler 00006 email : marco dot hugentobler at karto dot baug dot ethz dot ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef QGSSNAPPER_H 00019 #define QGSSNAPPER_H 00020 00021 #include "qgspoint.h" 00022 #include "qgstolerance.h" 00023 #include <QList> 00024 #include <QMultiMap> 00025 00026 class QgsMapRenderer; 00027 class QgsVectorLayer; 00028 class QPoint; 00029 00033 struct CORE_EXPORT QgsSnappingResult 00034 { 00036 QgsPoint snappedVertex; 00039 int snappedVertexNr; 00041 QgsPoint beforeVertex; 00044 int beforeVertexNr; 00046 QgsPoint afterVertex; 00049 int afterVertexNr; 00051 int snappedAtGeometry; 00053 const QgsVectorLayer* layer; 00054 }; 00055 00056 00057 00059 class CORE_EXPORT QgsSnapper 00060 { 00061 public: 00063 enum SnappingType 00064 { 00065 SnapToVertex, 00066 SnapToSegment, 00067 //snap to vertex and also to segment if no vertex is within the search tolerance 00068 SnapToVertexAndSegment 00069 }; 00070 00071 enum SnappingMode 00072 { 00074 SnapWithOneResult, 00077 SnapWithResultsForSamePosition, 00079 SnapWithResultsWithinTolerances 00080 }; 00081 00082 struct SnapLayer 00083 { 00085 QgsVectorLayer* mLayer; 00087 double mTolerance; 00089 QgsSnapper::SnappingType mSnapTo; 00091 QgsTolerance::UnitType mUnitType; 00092 }; 00093 00094 QgsSnapper( QgsMapRenderer* mapRender ); 00095 ~QgsSnapper(); 00101 int snapPoint( const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludePoints = QList<QgsPoint>() ); 00102 00103 //setters 00104 void setSnapLayers( const QList<QgsSnapper::SnapLayer>& snapLayers ); 00105 void setSnapMode( QgsSnapper::SnappingMode snapMode ); 00106 00107 private: 00109 QgsSnapper(); 00110 00112 void cleanResultList( QMultiMap<double, QgsSnappingResult>& list, const QList<QgsPoint>& excludeList ) const; 00113 00116 QgsMapRenderer* mMapRenderer; 00118 QgsSnapper::SnappingMode mSnapMode; 00120 QList<QgsSnapper::SnapLayer> mSnapLayers; 00121 }; 00122 00123 #endif