LCOV - code coverage report
Current view: top level - core - qgscadutils.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 1 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                               qgscadutils.h
       3                 :            :                              -------------------
       4                 :            :     begin                : September 2017
       5                 :            :     copyright            : (C) 2017 by Martin Dobias
       6                 :            :     email                : wonder dot sk at gmail dot com
       7                 :            :  ***************************************************************************/
       8                 :            : /***************************************************************************
       9                 :            :  *                                                                         *
      10                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      11                 :            :  *   it under the terms of the GNU General Public License as published by  *
      12                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      13                 :            :  *   (at your option) any later version.                                   *
      14                 :            :  *                                                                         *
      15                 :            :  ***************************************************************************/
      16                 :            : 
      17                 :            : #ifndef QGSCADUTILS_H
      18                 :            : #define QGSCADUTILS_H
      19                 :            : 
      20                 :            : #include "qgis_core.h"
      21                 :            : 
      22                 :            : #include "qgspointlocator.h"
      23                 :            : 
      24                 :            : class QgsSnappingUtils;
      25                 :            : 
      26                 :            : /**
      27                 :            :  * \ingroup core
      28                 :            :  * \brief The QgsCadUtils class provides routines for CAD editing.
      29                 :            :  *
      30                 :            :  * \since QGIS 3.0
      31                 :            :  */
      32                 :            : class CORE_EXPORT QgsCadUtils
      33                 :            : {
      34                 :            :   public:
      35                 :            : 
      36                 :            :     //! Structure with details of one constraint
      37                 :            :     struct AlignMapPointConstraint
      38                 :            :     {
      39                 :            :       AlignMapPointConstraint( bool locked = false, bool relative = false, double value = 0 )
      40                 :            :         : locked( locked )
      41                 :            :         , relative( relative )
      42                 :            :         , value( value )
      43                 :            :       {}
      44                 :            : 
      45                 :            :       //! Whether the constraint is active, i.e. should be considered
      46                 :            :       bool locked;
      47                 :            :       //! Whether the value is relative to previous value
      48                 :            :       bool relative;
      49                 :            :       //! Numeric value of the constraint (coordinate/distance in map units or angle in degrees)
      50                 :            :       double value;
      51                 :            :     };
      52                 :            : 
      53                 :            :     //! Structure defining all constraints for alignMapPoint() method
      54                 :            :     struct AlignMapPointContext
      55                 :            :     {
      56                 :            :       //! Snapping utils that will be used to snap point to map. Must not be NULLPTR.
      57                 :            :       QgsSnappingUtils *snappingUtils = nullptr;
      58                 :            :       //! Map units/pixel ratio from map canvas. Needed for
      59                 :            :       double mapUnitsPerPixel;
      60                 :            : 
      61                 :            :       //! Constraint for X coordinate
      62                 :            :       QgsCadUtils::AlignMapPointConstraint xConstraint;
      63                 :            :       //! Constraint for Y coordinate
      64                 :            :       QgsCadUtils::AlignMapPointConstraint yConstraint;
      65                 :            :       //! Constraint for distance
      66                 :            :       QgsCadUtils::AlignMapPointConstraint distanceConstraint;
      67                 :            :       //! Constraint for angle
      68                 :            :       QgsCadUtils::AlignMapPointConstraint angleConstraint;
      69                 :            :       //! Constraint for soft lock to a common angle
      70                 :            :       QgsCadUtils::AlignMapPointConstraint commonAngleConstraint;
      71                 :            : 
      72                 :            :       /**
      73                 :            :        * List of recent CAD points in map coordinates. These are used to turn relative constraints to absolute.
      74                 :            :        * First point is the most recent point. Currently using only "previous" point (index 1) and "penultimate"
      75                 :            :        * point (index 2) for alignment purposes.
      76                 :            :        */
      77                 :            :       QList<QgsPointXY> cadPointList;
      78                 :            : 
      79                 :            :       /**
      80                 :            :        * Dumps the context's properties, for debugging.
      81                 :            :        * \note Not available in Python bindings.
      82                 :            :        */
      83                 :            :       SIP_SKIP void dump() const;
      84                 :            :     };
      85                 :            : 
      86                 :            :     //! Structure returned from alignMapPoint() method
      87                 :          0 :     struct AlignMapPointOutput
      88                 :            :     {
      89                 :            :       //! Whether the combination of constraints is actually valid
      90                 :            :       bool valid;
      91                 :            : 
      92                 :            :       //! map point aligned according to the constraints
      93                 :            :       QgsPointXY finalMapPoint;
      94                 :            : 
      95                 :            :       /**
      96                 :            :        * Snapped point - only valid if actually used for something
      97                 :            :        * \since QGIS 3.14
      98                 :            :        */
      99                 :            :       QgsPointLocator::Match snapMatch;
     100                 :            : 
     101                 :            :       /**
     102                 :            :        * Snapped segment - only valid if actually used for something
     103                 :            :        * \deprecated will be removed in QGIS 4.0 - use snapMatch instead
     104                 :            :        */
     105                 :            :       QgsPointLocator::Match edgeMatch;
     106                 :            : 
     107                 :            :       //! Angle (in degrees) to which we have soft-locked ourselves (if not set it is -1)
     108                 :            :       double softLockCommonAngle;
     109                 :            :     };
     110                 :            : 
     111                 :            :     /**
     112                 :            :      * Applies X/Y/angle/distance constraints from the given context to a map point.
     113                 :            :      * Returns a structure containing aligned map point, whether the constraints are valid and
     114                 :            :      * some extra information.
     115                 :            :      */
     116                 :            :     static QgsCadUtils::AlignMapPointOutput alignMapPoint( const QgsPointXY &originalMapPoint, const QgsCadUtils::AlignMapPointContext &ctx );
     117                 :            : 
     118                 :            : };
     119                 :            : 
     120                 :            : #endif // QGSCADUTILS_H

Generated by: LCOV version 1.14