mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
105 lines
3.7 KiB
C++
105 lines
3.7 KiB
C++
/***************************************************************************
|
|
qgscadutils.h
|
|
-------------------
|
|
begin : September 2017
|
|
copyright : (C) 2017 by Martin Dobias
|
|
email : wonder dot sk at gmail dot 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. *
|
|
* *
|
|
***************************************************************************/
|
|
|
|
#ifndef QGSCADUTILS_H
|
|
#define QGSCADUTILS_H
|
|
|
|
#include "qgis_core.h"
|
|
|
|
#include "qgspointlocator.h"
|
|
|
|
class QgsSnappingUtils;
|
|
|
|
/**
|
|
* The QgsCadUtils class provides routines for CAD editing.
|
|
*
|
|
* \since QGIS 3.0
|
|
*/
|
|
class CORE_EXPORT QgsCadUtils
|
|
{
|
|
public:
|
|
|
|
//! Structure with details of one constraint
|
|
struct AlignMapPointConstraint
|
|
{
|
|
AlignMapPointConstraint( bool locked = false, bool relative = false, double value = 0 )
|
|
: locked( locked )
|
|
, relative( relative )
|
|
, value( value )
|
|
{}
|
|
|
|
//! Whether the constraint is active, i.e. should be considered
|
|
bool locked;
|
|
//! Whether the value is relative to previous value
|
|
bool relative;
|
|
//! Numeric value of the constraint (coordinate/distance in map units or angle in degrees)
|
|
double value;
|
|
};
|
|
|
|
//! Structure defining all constraints for alignMapPoint() method
|
|
struct AlignMapPointContext
|
|
{
|
|
//! Snapping utils that will be used to snap point to map. Must not be null
|
|
QgsSnappingUtils *snappingUtils;
|
|
//! Map units/pixel ratio from map canvas. Needed for
|
|
double mapUnitsPerPixel;
|
|
|
|
//! Constraint for X coordinate
|
|
AlignMapPointConstraint xConstraint;
|
|
//! Constraint for Y coordinate
|
|
AlignMapPointConstraint yConstraint;
|
|
//! Constraint for distance
|
|
AlignMapPointConstraint distanceConstraint;
|
|
//! Constraint for angle
|
|
AlignMapPointConstraint angleConstraint;
|
|
//! Constraint for soft lock to a common angle
|
|
AlignMapPointConstraint commonAngleConstraint;
|
|
|
|
//! List of recent CAD points in map coordinates. These are used to turn relative constraints to absolute.
|
|
//! First point is the most recent point. Currently using only "previous" point (index 1) and "penultimate"
|
|
//! point (index 2) for alignment purposes.
|
|
QList<QgsPointXY> cadPointList;
|
|
|
|
void dump() const;
|
|
};
|
|
|
|
//! Structure returned from alignMapPoint() method
|
|
struct AlignMapPointOutput
|
|
{
|
|
//! Whether the combination of constraints is actually valid
|
|
bool valid;
|
|
|
|
//! map point aligned according to the constraints
|
|
QgsPointXY finalMapPoint;
|
|
|
|
//! Snapped segment - only valid if actually used for something
|
|
QgsPointLocator::Match edgeMatch;
|
|
|
|
//! Angle (in degrees) to which we have soft-locked ourselves (if not set it is -1)
|
|
int softLockCommonAngle;
|
|
};
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
static AlignMapPointOutput alignMapPoint( const QgsPointXY &originalMapPoint, const AlignMapPointContext &ctx );
|
|
|
|
};
|
|
|
|
#endif // QGSCADUTILS_H
|