Skip to content
Permalink
Browse files

Sip bindings for editing and cad map tools

  • Loading branch information
m-kuhn authored and 3nids committed Sep 11, 2015
1 parent dae0d4a commit 3831668f2e0885461103cf4e91dd2790098485b0
@@ -18,6 +18,7 @@

%Include qgisinterface.sip
%Include qgsannotationitem.sip
%Include qgsadvanceddigitizingdockwidget.sip
%Include qgsattributeeditor.sip
%Include qgsattributeeditorcontext.sip
%Include qgsattributedialog.sip
@@ -63,6 +64,7 @@
%Include qgsfilterlineedit.sip
%Include qgsformannotationitem.sip
%Include qgsgenericprojectionselector.sip
%Include qgsgeometryrubberband.sip
%Include qgshighlight.sip
%Include qgshistogramwidget.sip
%Include qgshtmlannotationitem.sip
@@ -83,6 +85,9 @@
%Include qgsmapoverviewcanvas.sip
%Include qgsmaptip.sip
%Include qgsmaptool.sip
%Include qgsmaptooladvanceddigitizing.sip
%Include qgsmaptoolcapture.sip
%Include qgsmaptooledit.sip
%Include qgsmaptoolemitpoint.sip
%Include qgsmaptoolidentify.sip
%Include qgsmaptoolidentifyfeature.sip
@@ -0,0 +1,168 @@
/***************************************************************************
qgsadvanceddigitizingdock.h - dock for CAD tools
----------------------
begin : October 2014
copyright : (C) Denis Rouzaud
email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/


/**
* @brief The QgsAdvancedDigitizingDock class is a dockable widget
* used to handle the CAD tools on top of a selection of map tools.
* It handles both the UI and the constraints. Constraints are applied
* by implemeting filters called from QgsMapToolAdvancedDigitizing.
*/
class QgsAdvancedDigitizingDockWidget : QDockWidget
{
%TypeHeaderCode
#include <qgsadvanceddigitizingdockwidget.h>
%End
public:

/**
* @brief The CadCapacity enum defines the possible constraints to be set
* depending on the number of points in the CAD point list (the list of points
* currently digitized)
*/
enum CadCapacity
{
AbsoluteAngle = 1, // = Azimuth
RelativeAngle = 2, // also for parallel and perpendicular
RelativeCoordinates = 4, // this corresponds to distance and relative coordinates
};

enum AdditionalConstraint
{
NoConstraint,
Perpendicular,
Parallel
};

/**
* @brief The CadConstraint is an abstract class for all basic constraints (angle/distance/x/y).
* It contains all values (locked, value, relative) and pointers to corresponding widgets.
* @note Relative is not mandatory since it is not used for distance.
*/
class CadConstraint
{
public:
enum LockMode
{
NoLock,
SoftLock,
HardLock
};

CadConstraint( QLineEdit* lineEdit, QToolButton* lockerButton, QToolButton* relativeButton = 0 );

LockMode lockMode() const;
bool isLocked() const;
bool relative() const;
double value() const;

QLineEdit* lineEdit() const;

void setLockMode( LockMode mode );
void setRelative( bool relative );
void setValue( double value );

void toggleLocked();
void toggleRelative();
};

//! performs the intersection of a circle and a line
//! @note from the two solutions, the intersection will be set to the closest point
static bool lineCircleIntersection( const QgsPoint& center, const double radius, const QList<QgsPoint>& segment, QgsPoint& intersection );

explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas* canvas, QWidget *parent = 0 );

void hideEvent( QHideEvent* );

bool canvasPressEvent( QgsMapMouseEvent* e );
bool canvasReleaseEvent( QgsMapMouseEvent* e , bool captureSegment );
bool canvasMoveEvent( QgsMapMouseEvent* e );
bool canvasKeyPressEventFilter( QKeyEvent *e );

//! apply the CAD constraints. The will modify the position of the map event in map coordinates by applying the CAD constraints.
//! @return false if no solution was found (invalid constraints)
virtual bool applyConstraints( QgsMapMouseEvent* e );

void clear();

QgsMapMouseEvent::SnappingMode snappingMode();

//! key press event on the dock
void keyPressEvent( QKeyEvent* e );

//! determines if CAD tools are enabled or if map tools behaves "nomally"
bool cadEnabled() const;

//! construction mode is used to draw intermediate points. These points won't be given any further (i.e. to the map tools)
bool constructionMode() const;

//! Additional constraints are used to place perpendicular/parallel segments to snapped segments on the canvas
AdditionalConstraint additionalConstraint() const;
const CadConstraint* constraintAngle()const;
const CadConstraint* constraintDistance() const;
const CadConstraint* constraintX() const;
const CadConstraint* constraintY() const;
bool commonAngleConstraint() const;

/** Helpers for the CAD point list. The CAD point list is the list of points
* currently digitized. It contains both "normal" points and intermediate points (construction mode).
*/
QgsPoint currentPoint( bool* exists = 0 ) const;
QgsPoint previousPoint( bool* exists = 0 ) const;
QgsPoint penultimatePoint( bool* exists = 0 ) const;
int pointsCount() const;
bool snappedToVertex() const;
const QList<QgsPoint>& snappedSegment() const;

//! return the action used to enable/disable the tools
QAction* enableAction();

void enable();

void disable();

signals:
void pushWarning( const QString& message );

void popWarning();

void pointChanged( const QgsPoint& point );

private slots:
//! set the additiona constraint by clicking on the perpendicular/parallel buttons
void addtionalConstraintClicked( bool activated );

//! lock/unlock a constraint and set its value
void lockConstraint( bool activate = true );

//! unlock all constraints
void releaseLocks();

//! set the relative properties of constraints
void setConstraintRelative( bool activate );

//! activate/deactivate tools. It is called when tools are activated manually (from the GUI)
//! it will call setCadEnabled to properly update the UI.
void activateCad( bool enabled );

//! enable/disable construction mode (events are not forwarded to the map tool)
void setConstructionMode( bool enabled );

//! settings button triggered
void settingsButtonTriggered( QAction* action );

private:
bool eventFilter( QObject *obj, QEvent *event );
};
@@ -0,0 +1,77 @@
/***************************************************************************
qgsgeometryrubberband.h
-----------------------
begin : December 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/** A rubberband class for QgsAbstractGeometryV2 (considering curved geometries)*/
class QgsGeometryRubberBand: QgsMapCanvasItem
{
%TypeHeaderCode
#include "qgsgeometryrubberband.h"
%End
public:
enum IconType
{
/**
* No icon is used
*/
ICON_NONE,
/**
* A cross is used to highlight points (+)
*/
ICON_CROSS,
/**
* A cross is used to highlight points (x)
*/
ICON_X,
/**
* A box is used to highlight points (□)
*/
ICON_BOX,
/**
* A circle is used to highlight points (○)
*/
ICON_CIRCLE,
/**
* A full box is used to highlight points (■)
*/
ICON_FULL_BOX
};

QgsGeometryRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geomType = QGis::Line );
~QgsGeometryRubberBand();

/** Sets geometry (takes ownership). Geometry is expected to be in map coordinates */
void setGeometry( QgsAbstractGeometryV2* geom );
/** Returns a pointer to the geometry*/
const QgsAbstractGeometryV2* geometry();
/** Moves vertex to new position (in map coordinates)*/
void moveVertex( const QgsVertexId& id, const QgsPointV2& newPos );
/** Sets fill color for vertex markers*/
void setFillColor( const QColor& c );
/** Sets outline color for vertex markes*/
void setOutlineColor( const QColor& c );
/** Sets outline width*/
void setOutlineWidth( int width );
/** Sets pen style*/
void setLineStyle( Qt::PenStyle penStyle );
/** Sets brush style*/
void setBrushStyle( Qt::BrushStyle brushStyle );
/** Sets vertex marker icon type*/
void setIconType( IconType iconType );

protected:
virtual void paint( QPainter* painter );
};
@@ -0,0 +1,100 @@
/***************************************************************************
qgsmaptooladvanceddigitizing.h - map tool with event in map coordinates
----------------------
begin : October 2014
copyright : (C) Denis Rouzaud
email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* @brief The QgsMapToolAdvancedDigitizing class is a QgsMapTool whcih gives event directly in map coordinates and allows filtering its events.
* Events from QgsMapTool are caught and their QMouseEvent are transformed into QgsMapMouseEvent (with map coordinates).
* Events are then forwarded to corresponding virtual methods which can be reimplemented in subclasses.
* An event filter can be set on the map tool to filter and modify the events in map coordinates (@see QgsMapToolMapEventFilter).
* @note at the moment, the event filter is used by the CAD tools (@see QgsCadDocWidget).
* @note the event filter definition is not exposed in python API to avoid any unexpected behavior.
*/
class QgsMapToolAdvancedDigitizing : QgsMapToolEdit
{
%TypeHeaderCode
#include "qgsmaptooladvanceddigitizing.h"
%End
public:
enum CaptureMode
{
CaptureNone,
CapturePoint,
CaptureLine,
CapturePolygon
};

explicit QgsMapToolAdvancedDigitizing( QgsMapCanvas* canvas, QgsAdvancedDigitizingDockWidget* cadDockWidget );

~QgsMapToolAdvancedDigitizing();

//! catch the mouse press event, filters it, transforms it to map coordinates and send it to virtual method
void canvasPressEvent( QgsMapMouseEvent* e );
//! catch the mouse release event, filters it, transforms it to map coordinates and send it to virtual method
void canvasReleaseEvent( QgsMapMouseEvent* e );
//! catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual method
void canvasMoveEvent( QgsMapMouseEvent* e );

/**
* The capture mode
*
* @return Capture mode
*/
CaptureMode mode() const;

/**
* Registers this maptool with the cad dock widget
*/
void activate();

/**
* Unregisters this maptool from the cad dock widget
*/
void deactivate();

QgsAdvancedDigitizingDockWidget* cadDockWidget() const;

protected:
/**
* this method when subclassing this class.
* This will receive adapted events from the cad system whenever a
* canvasPressEvent is triggered and it's not hidden by the cad's
* construction mode.
*
* @param e Mouse events prepared by the cad system
*/
virtual void cadCanvasPressEvent( QgsMapMouseEvent* e );


/**
* this method when subclassing this class.
* This will receive adapted events from the cad system whenever a
* canvasReleaseEvent is triggered and it's not hidden by the cad's
* construction mode.
*
* @param e Mouse events prepared by the cad system
*/
virtual void cadCanvasReleaseEvent( QgsMapMouseEvent* e );


/**
* this method when subclassing this class.
* This will receive adapted events from the cad system whenever a
* canvasMoveEvent is triggered and it's not hidden by the cad's
* construction mode.
*
* @param e Mouse events prepared by the cad system
*/
virtual void cadCanvasMoveEvent( QgsMapMouseEvent* e );
};

0 comments on commit 3831668

Please sign in to comment.
You can’t perform that action at this time.