Quantum GIS API Documentation
1.8
|
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 "qgsfeature.h" 00024 00025 #include <QList> 00026 #include <QMultiMap> 00027 00028 class QgsMapRenderer; 00029 class QgsVectorLayer; 00030 class QPoint; 00031 00035 struct CORE_EXPORT QgsSnappingResult 00036 { 00038 QgsPoint snappedVertex; 00041 int snappedVertexNr; 00043 QgsPoint beforeVertex; 00046 int beforeVertexNr; 00048 QgsPoint afterVertex; 00051 int afterVertexNr; 00053 QgsFeatureId snappedAtGeometry; 00055 const QgsVectorLayer* layer; 00056 }; 00057 00058 00059 00061 class CORE_EXPORT QgsSnapper 00062 { 00063 public: 00065 enum SnappingType 00066 { 00067 SnapToVertex, 00068 SnapToSegment, 00069 //snap to vertex and also to segment if no vertex is within the search tolerance 00070 SnapToVertexAndSegment 00071 }; 00072 00073 enum SnappingMode 00074 { 00076 SnapWithOneResult, 00079 SnapWithResultsForSamePosition, 00081 SnapWithResultsWithinTolerances 00082 }; 00083 00084 struct SnapLayer 00085 { 00087 QgsVectorLayer* mLayer; 00089 double mTolerance; 00091 QgsSnapper::SnappingType mSnapTo; 00093 QgsTolerance::UnitType mUnitType; 00094 }; 00095 00096 QgsSnapper( QgsMapRenderer* mapRender ); 00097 ~QgsSnapper(); 00103 int snapPoint( const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludePoints = QList<QgsPoint>() ); 00104 00105 //setters 00106 void setSnapLayers( const QList<QgsSnapper::SnapLayer>& snapLayers ); 00107 void setSnapMode( QgsSnapper::SnappingMode snapMode ); 00108 00109 private: 00111 QgsSnapper(); 00112 00114 void cleanResultList( QMultiMap<double, QgsSnappingResult>& list, const QList<QgsPoint>& excludeList ) const; 00115 00118 QgsMapRenderer* mMapRenderer; 00120 QgsSnapper::SnappingMode mSnapMode; 00122 QList<QgsSnapper::SnapLayer> mSnapLayers; 00123 }; 00124 00125 #endif