|
| 1 | +/*************************************************************************** |
| 2 | + qgsadvanceddigitizingdock.h - dock for CAD tools |
| 3 | + ---------------------- |
| 4 | + begin : October 2014 |
| 5 | + copyright : (C) Denis Rouzaud |
| 6 | + email : denis.rouzaud@gmail.com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | + |
| 17 | +/** |
| 18 | + * @brief The QgsAdvancedDigitizingDock class is a dockable widget |
| 19 | + * used to handle the CAD tools on top of a selection of map tools. |
| 20 | + * It handles both the UI and the constraints. Constraints are applied |
| 21 | + * by implemeting filters called from QgsMapToolAdvancedDigitizing. |
| 22 | + */ |
| 23 | +class QgsAdvancedDigitizingDockWidget : QDockWidget |
| 24 | +{ |
| 25 | +%TypeHeaderCode |
| 26 | +#include <qgsadvanceddigitizingdockwidget.h> |
| 27 | +%End |
| 28 | + public: |
| 29 | + |
| 30 | + /** |
| 31 | + * @brief The CadCapacity enum defines the possible constraints to be set |
| 32 | + * depending on the number of points in the CAD point list (the list of points |
| 33 | + * currently digitized) |
| 34 | + */ |
| 35 | + enum CadCapacity |
| 36 | + { |
| 37 | + AbsoluteAngle = 1, // = Azimuth |
| 38 | + RelativeAngle = 2, // also for parallel and perpendicular |
| 39 | + RelativeCoordinates = 4, // this corresponds to distance and relative coordinates |
| 40 | + }; |
| 41 | + |
| 42 | + enum AdditionalConstraint |
| 43 | + { |
| 44 | + NoConstraint, |
| 45 | + Perpendicular, |
| 46 | + Parallel |
| 47 | + }; |
| 48 | + |
| 49 | + /** |
| 50 | + * @brief The CadConstraint is an abstract class for all basic constraints (angle/distance/x/y). |
| 51 | + * It contains all values (locked, value, relative) and pointers to corresponding widgets. |
| 52 | + * @note Relative is not mandatory since it is not used for distance. |
| 53 | + */ |
| 54 | + class CadConstraint |
| 55 | + { |
| 56 | + public: |
| 57 | + enum LockMode |
| 58 | + { |
| 59 | + NoLock, |
| 60 | + SoftLock, |
| 61 | + HardLock |
| 62 | + }; |
| 63 | + |
| 64 | + CadConstraint( QLineEdit* lineEdit, QToolButton* lockerButton, QToolButton* relativeButton = 0 ); |
| 65 | + |
| 66 | + LockMode lockMode() const; |
| 67 | + bool isLocked() const; |
| 68 | + bool relative() const; |
| 69 | + double value() const; |
| 70 | + |
| 71 | + QLineEdit* lineEdit() const; |
| 72 | + |
| 73 | + void setLockMode( LockMode mode ); |
| 74 | + void setRelative( bool relative ); |
| 75 | + void setValue( double value ); |
| 76 | + |
| 77 | + void toggleLocked(); |
| 78 | + void toggleRelative(); |
| 79 | + }; |
| 80 | + |
| 81 | + //! performs the intersection of a circle and a line |
| 82 | + //! @note from the two solutions, the intersection will be set to the closest point |
| 83 | + static bool lineCircleIntersection( const QgsPoint& center, const double radius, const QList<QgsPoint>& segment, QgsPoint& intersection ); |
| 84 | + |
| 85 | + explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas* canvas, QWidget *parent = 0 ); |
| 86 | + |
| 87 | + void hideEvent( QHideEvent* ); |
| 88 | + |
| 89 | + bool canvasPressEvent( QgsMapMouseEvent* e ); |
| 90 | + bool canvasReleaseEvent( QgsMapMouseEvent* e , bool captureSegment ); |
| 91 | + bool canvasMoveEvent( QgsMapMouseEvent* e ); |
| 92 | + bool canvasKeyPressEventFilter( QKeyEvent *e ); |
| 93 | + |
| 94 | + //! apply the CAD constraints. The will modify the position of the map event in map coordinates by applying the CAD constraints. |
| 95 | + //! @return false if no solution was found (invalid constraints) |
| 96 | + virtual bool applyConstraints( QgsMapMouseEvent* e ); |
| 97 | + |
| 98 | + void clear(); |
| 99 | + |
| 100 | + QgsMapMouseEvent::SnappingMode snappingMode(); |
| 101 | + |
| 102 | + //! key press event on the dock |
| 103 | + void keyPressEvent( QKeyEvent* e ); |
| 104 | + |
| 105 | + //! determines if CAD tools are enabled or if map tools behaves "nomally" |
| 106 | + bool cadEnabled() const; |
| 107 | + |
| 108 | + //! construction mode is used to draw intermediate points. These points won't be given any further (i.e. to the map tools) |
| 109 | + bool constructionMode() const; |
| 110 | + |
| 111 | + //! Additional constraints are used to place perpendicular/parallel segments to snapped segments on the canvas |
| 112 | + AdditionalConstraint additionalConstraint() const; |
| 113 | + const CadConstraint* constraintAngle()const; |
| 114 | + const CadConstraint* constraintDistance() const; |
| 115 | + const CadConstraint* constraintX() const; |
| 116 | + const CadConstraint* constraintY() const; |
| 117 | + bool commonAngleConstraint() const; |
| 118 | + |
| 119 | + /** Helpers for the CAD point list. The CAD point list is the list of points |
| 120 | + * currently digitized. It contains both "normal" points and intermediate points (construction mode). |
| 121 | + */ |
| 122 | + QgsPoint currentPoint( bool* exists = 0 ) const; |
| 123 | + QgsPoint previousPoint( bool* exists = 0 ) const; |
| 124 | + QgsPoint penultimatePoint( bool* exists = 0 ) const; |
| 125 | + int pointsCount() const; |
| 126 | + bool snappedToVertex() const; |
| 127 | + const QList<QgsPoint>& snappedSegment() const; |
| 128 | + |
| 129 | + //! return the action used to enable/disable the tools |
| 130 | + QAction* enableAction(); |
| 131 | + |
| 132 | + void enable(); |
| 133 | + |
| 134 | + void disable(); |
| 135 | + |
| 136 | + signals: |
| 137 | + void pushWarning( const QString& message ); |
| 138 | + |
| 139 | + void popWarning(); |
| 140 | + |
| 141 | + void pointChanged( const QgsPoint& point ); |
| 142 | + |
| 143 | + private slots: |
| 144 | + //! set the additiona constraint by clicking on the perpendicular/parallel buttons |
| 145 | + void addtionalConstraintClicked( bool activated ); |
| 146 | + |
| 147 | + //! lock/unlock a constraint and set its value |
| 148 | + void lockConstraint( bool activate = true ); |
| 149 | + |
| 150 | + //! unlock all constraints |
| 151 | + void releaseLocks(); |
| 152 | + |
| 153 | + //! set the relative properties of constraints |
| 154 | + void setConstraintRelative( bool activate ); |
| 155 | + |
| 156 | + //! activate/deactivate tools. It is called when tools are activated manually (from the GUI) |
| 157 | + //! it will call setCadEnabled to properly update the UI. |
| 158 | + void activateCad( bool enabled ); |
| 159 | + |
| 160 | + //! enable/disable construction mode (events are not forwarded to the map tool) |
| 161 | + void setConstructionMode( bool enabled ); |
| 162 | + |
| 163 | + //! settings button triggered |
| 164 | + void settingsButtonTriggered( QAction* action ); |
| 165 | + |
| 166 | + private: |
| 167 | + bool eventFilter( QObject *obj, QEvent *event ); |
| 168 | +}; |
0 commit comments