Skip to content

Commit

Permalink
Merge pull request #5183 from wonder-sk/cad-utils
Browse files Browse the repository at this point in the history
Refactor CAD editing alignment logic to new QgsCadUtils class
  • Loading branch information
wonder-sk authored Oct 3, 2017
2 parents 9256d00 + 0bffe1c commit 7874d4b
Show file tree
Hide file tree
Showing 11 changed files with 1,013 additions and 348 deletions.
1 change: 1 addition & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ QgsAdvancedDigitizingDockWidget {#qgis_api_break_3_0_QgsAdvancedDigitizin

- canvasPressEvent(), canvasReleaseEvent(), canvasMoveEvent() were removed. Handling of events is done in QgsMapToolAdvancedDigitizing.
- snappingMode() was removed. Advanced digitizing now always uses project's snapping configuration.
- lineCircleIntersection() was removed


QgsApplication {#qgis_api_break_3_0_QgsApplication}
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
%Include qgscachedfeatureiterator.sip
%Include qgscacheindex.sip
%Include qgscacheindexfeatureid.sip
%Include qgscadutils.sip
%Include qgsclipper.sip
%Include qgscolorramp.sip
%Include qgscolorscheme.sip
Expand Down
123 changes: 123 additions & 0 deletions python/core/qgscadutils.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgscadutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsCadUtils
{
%Docstring
The QgsCadUtils class provides routines for CAD editing.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgscadutils.h"
%End
public:

struct AlignMapPointConstraint
{
AlignMapPointConstraint( bool locked = false, bool relative = false, double value = 0 );

bool locked;
%Docstring
Whether the constraint is active, i.e. should be considered
%End
bool relative;
%Docstring
Whether the value is relative to previous value
%End
double value;
%Docstring
Numeric value of the constraint (coordinate/distance in map units or angle in degrees)
%End
};

struct AlignMapPointContext
{
QgsSnappingUtils *snappingUtils;
%Docstring
Snapping utils that will be used to snap point to map. Must not be null
%End
double mapUnitsPerPixel;
%Docstring
Map units/pixel ratio from map canvas. Needed for
%End

QgsCadUtils::AlignMapPointConstraint xConstraint;
%Docstring
Constraint for X coordinate
%End
QgsCadUtils::AlignMapPointConstraint yConstraint;
%Docstring
Constraint for Y coordinate
%End
QgsCadUtils::AlignMapPointConstraint distanceConstraint;
%Docstring
Constraint for distance
%End
QgsCadUtils::AlignMapPointConstraint angleConstraint;
%Docstring
Constraint for angle
%End
QgsCadUtils::AlignMapPointConstraint commonAngleConstraint;
%Docstring
Constraint for soft lock to a common angle
%End

QList<QgsPointXY> cadPointList;
%Docstring
point (index 2) for alignment purposes.
%End

void dump() const;
};

struct AlignMapPointOutput
{
bool valid;
%Docstring
Whether the combination of constraints is actually valid
%End

QgsPointXY finalMapPoint;
%Docstring
map point aligned according to the constraints
%End

QgsPointLocator::Match edgeMatch;
%Docstring
Snapped segment - only valid if actually used for something
%End

int softLockCommonAngle;
%Docstring
Angle (in degrees) to which we have soft-locked ourselves (if not set it is -1)
%End
};

static QgsCadUtils::AlignMapPointOutput alignMapPoint( const QgsPointXY &originalMapPoint, const QgsCadUtils::AlignMapPointContext &ctx );
%Docstring
Applies X/Y/angle/distance constraints from the given context to a map point.
Returns a structure containing aligned map point, whether the constraints are valid and
some extra information.
:rtype: QgsCadUtils.AlignMapPointOutput
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgscadutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
9 changes: 0 additions & 9 deletions python/gui/qgsadvanceddigitizingdockwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@




class QgsAdvancedDigitizingDockWidget : QgsDockWidget
{
%Docstring
Expand Down Expand Up @@ -151,14 +150,6 @@ class QgsAdvancedDigitizingDockWidget : QgsDockWidget

};

static bool lineCircleIntersection( const QgsPointXY &center, const double radius, const QList<QgsPointXY> &segment, QgsPointXY &intersection );
%Docstring
.. note::

from the two solutions, the intersection will be set to the closest point
:rtype: bool
%End

explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas *canvas, QWidget *parent = 0 );
%Docstring
Create an advanced digitizing dock widget
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ SET(QGIS_CORE_SRCS
qgscachedfeatureiterator.cpp
qgscacheindex.cpp
qgscacheindexfeatureid.cpp
qgscadutils.cpp
qgsclipper.cpp
qgscolorramp.cpp
qgscolorscheme.cpp
Expand Down Expand Up @@ -792,6 +793,7 @@ SET(QGIS_CORE_HDRS
qgscachedfeatureiterator.h
qgscacheindex.h
qgscacheindexfeatureid.h
qgscadutils.h
qgsclipper.h
qgscolorramp.h
qgscolorscheme.h
Expand Down
Loading

0 comments on commit 7874d4b

Please sign in to comment.