Skip to content

Commit 3831668

Browse files
m-kuhn3nids
authored andcommitted
Sip bindings for editing and cad map tools
1 parent dae0d4a commit 3831668

File tree

7 files changed

+472
-1
lines changed

7 files changed

+472
-1
lines changed

python/gui/gui.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
%Include qgisinterface.sip
2020
%Include qgsannotationitem.sip
21+
%Include qgsadvanceddigitizingdockwidget.sip
2122
%Include qgsattributeeditor.sip
2223
%Include qgsattributeeditorcontext.sip
2324
%Include qgsattributedialog.sip
@@ -63,6 +64,7 @@
6364
%Include qgsfilterlineedit.sip
6465
%Include qgsformannotationitem.sip
6566
%Include qgsgenericprojectionselector.sip
67+
%Include qgsgeometryrubberband.sip
6668
%Include qgshighlight.sip
6769
%Include qgshistogramwidget.sip
6870
%Include qgshtmlannotationitem.sip
@@ -83,6 +85,9 @@
8385
%Include qgsmapoverviewcanvas.sip
8486
%Include qgsmaptip.sip
8587
%Include qgsmaptool.sip
88+
%Include qgsmaptooladvanceddigitizing.sip
89+
%Include qgsmaptoolcapture.sip
90+
%Include qgsmaptooledit.sip
8691
%Include qgsmaptoolemitpoint.sip
8792
%Include qgsmaptoolidentify.sip
8893
%Include qgsmaptoolidentifyfeature.sip
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
};

python/gui/qgsgeometryrubberband.sip

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/***************************************************************************
2+
qgsgeometryrubberband.h
3+
-----------------------
4+
begin : December 2014
5+
copyright : (C) 2014 by Marco Hugentobler
6+
email : marco at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
/** A rubberband class for QgsAbstractGeometryV2 (considering curved geometries)*/
19+
class QgsGeometryRubberBand: QgsMapCanvasItem
20+
{
21+
%TypeHeaderCode
22+
#include "qgsgeometryrubberband.h"
23+
%End
24+
public:
25+
enum IconType
26+
{
27+
/**
28+
* No icon is used
29+
*/
30+
ICON_NONE,
31+
/**
32+
* A cross is used to highlight points (+)
33+
*/
34+
ICON_CROSS,
35+
/**
36+
* A cross is used to highlight points (x)
37+
*/
38+
ICON_X,
39+
/**
40+
* A box is used to highlight points (□)
41+
*/
42+
ICON_BOX,
43+
/**
44+
* A circle is used to highlight points (○)
45+
*/
46+
ICON_CIRCLE,
47+
/**
48+
* A full box is used to highlight points (■)
49+
*/
50+
ICON_FULL_BOX
51+
};
52+
53+
QgsGeometryRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geomType = QGis::Line );
54+
~QgsGeometryRubberBand();
55+
56+
/** Sets geometry (takes ownership). Geometry is expected to be in map coordinates */
57+
void setGeometry( QgsAbstractGeometryV2* geom );
58+
/** Returns a pointer to the geometry*/
59+
const QgsAbstractGeometryV2* geometry();
60+
/** Moves vertex to new position (in map coordinates)*/
61+
void moveVertex( const QgsVertexId& id, const QgsPointV2& newPos );
62+
/** Sets fill color for vertex markers*/
63+
void setFillColor( const QColor& c );
64+
/** Sets outline color for vertex markes*/
65+
void setOutlineColor( const QColor& c );
66+
/** Sets outline width*/
67+
void setOutlineWidth( int width );
68+
/** Sets pen style*/
69+
void setLineStyle( Qt::PenStyle penStyle );
70+
/** Sets brush style*/
71+
void setBrushStyle( Qt::BrushStyle brushStyle );
72+
/** Sets vertex marker icon type*/
73+
void setIconType( IconType iconType );
74+
75+
protected:
76+
virtual void paint( QPainter* painter );
77+
};
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/***************************************************************************
2+
qgsmaptooladvanceddigitizing.h - map tool with event in map coordinates
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+
* @brief The QgsMapToolAdvancedDigitizing class is a QgsMapTool whcih gives event directly in map coordinates and allows filtering its events.
18+
* Events from QgsMapTool are caught and their QMouseEvent are transformed into QgsMapMouseEvent (with map coordinates).
19+
* Events are then forwarded to corresponding virtual methods which can be reimplemented in subclasses.
20+
* An event filter can be set on the map tool to filter and modify the events in map coordinates (@see QgsMapToolMapEventFilter).
21+
* @note at the moment, the event filter is used by the CAD tools (@see QgsCadDocWidget).
22+
* @note the event filter definition is not exposed in python API to avoid any unexpected behavior.
23+
*/
24+
class QgsMapToolAdvancedDigitizing : QgsMapToolEdit
25+
{
26+
%TypeHeaderCode
27+
#include "qgsmaptooladvanceddigitizing.h"
28+
%End
29+
public:
30+
enum CaptureMode
31+
{
32+
CaptureNone,
33+
CapturePoint,
34+
CaptureLine,
35+
CapturePolygon
36+
};
37+
38+
explicit QgsMapToolAdvancedDigitizing( QgsMapCanvas* canvas, QgsAdvancedDigitizingDockWidget* cadDockWidget );
39+
40+
~QgsMapToolAdvancedDigitizing();
41+
42+
//! catch the mouse press event, filters it, transforms it to map coordinates and send it to virtual method
43+
void canvasPressEvent( QgsMapMouseEvent* e );
44+
//! catch the mouse release event, filters it, transforms it to map coordinates and send it to virtual method
45+
void canvasReleaseEvent( QgsMapMouseEvent* e );
46+
//! catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual method
47+
void canvasMoveEvent( QgsMapMouseEvent* e );
48+
49+
/**
50+
* The capture mode
51+
*
52+
* @return Capture mode
53+
*/
54+
CaptureMode mode() const;
55+
56+
/**
57+
* Registers this maptool with the cad dock widget
58+
*/
59+
void activate();
60+
61+
/**
62+
* Unregisters this maptool from the cad dock widget
63+
*/
64+
void deactivate();
65+
66+
QgsAdvancedDigitizingDockWidget* cadDockWidget() const;
67+
68+
protected:
69+
/**
70+
* this method when subclassing this class.
71+
* This will receive adapted events from the cad system whenever a
72+
* canvasPressEvent is triggered and it's not hidden by the cad's
73+
* construction mode.
74+
*
75+
* @param e Mouse events prepared by the cad system
76+
*/
77+
virtual void cadCanvasPressEvent( QgsMapMouseEvent* e );
78+
79+
80+
/**
81+
* this method when subclassing this class.
82+
* This will receive adapted events from the cad system whenever a
83+
* canvasReleaseEvent is triggered and it's not hidden by the cad's
84+
* construction mode.
85+
*
86+
* @param e Mouse events prepared by the cad system
87+
*/
88+
virtual void cadCanvasReleaseEvent( QgsMapMouseEvent* e );
89+
90+
91+
/**
92+
* this method when subclassing this class.
93+
* This will receive adapted events from the cad system whenever a
94+
* canvasMoveEvent is triggered and it's not hidden by the cad's
95+
* construction mode.
96+
*
97+
* @param e Mouse events prepared by the cad system
98+
*/
99+
virtual void cadCanvasMoveEvent( QgsMapMouseEvent* e );
100+
};

0 commit comments

Comments
 (0)