forked from geosim/QAD
-
Notifications
You must be signed in to change notification settings - Fork 13
/
qad_point.py
162 lines (118 loc) · 5.54 KB
/
qad_point.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
classe per la gestione dei punti
-------------------
begin : 2018-12-27
copyright : iiiii
email : hhhhh
developers : bbbbb aaaaa ggggg
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.core import *
from qgis.gui import *
import math
from . import qad_utils
#===============================================================================
# QadPoint point class derivato da QgsPointXY
#===============================================================================
class QadPoint(QgsPointXY):
def __init__(self, point = None):
QgsPointXY.__init__(self)
if point is not None:
self.set(point)
def whatIs(self):
# obbligatoria
return "POINT"
#============================================================================
# isClosed
#============================================================================
def isClosed(self):
return False
def set(self, point):
QgsPointXY.set(self, point.x(), point.y())
return self
def transform(self, coordTransform):
# obbligatoria
"""Transform this geometry as described by CoordinateTransform ct."""
self.set(coordTransform.transform(self))
def transformFromCRSToCRS(self, sourceCRS, destCRS):
# obbligatoria
"""Transform this geometry as described by CRS."""
if (sourceCRS is not None) and (destCRS is not None) and sourceCRS != destCRS:
coordTransform = QgsCoordinateTransform(sourceCRS, destCRS, QgsProject.instance()) # trasformo le coord
self.transform(coordTransform)
def __eq__(self, point):
# obbligatoria
"""self == other"""
return qad_utils.ptNear(self, point)
def __ne__(self, point):
"""self != other"""
return not qad_utils.ptNear(self, point)
#===============================================================================
# getBoundingBox
#===============================================================================
def getBoundingBox(self):
"""
la funzione ritorna il rettangolo che racchiude il punto.
"""
return QgsRectangle(self.x(), self.y(), self.x(), self.y())
def equals(self, pt):
# uguali geometricamente
return self.__eq__(pt)
def copy(self):
# obbligatoria
return QadPoint(self)
#===============================================================================
# asGeom
#===============================================================================
def asGeom(self, wkbType = QgsWkbTypes.LineString, tolerance2ApproxCurve = None, atLeastNSegment = None):
"""
la funzione ritorna il punto in forma di QgsGeometry.
wkbType, tolerance2ApproxCurve e atLeastNSegment sono dichiarati solo per compatibilità
"""
flatType = QgsWkbTypes.flatType(wkbType)
if flatType == QgsWkbTypes.MultiPoint:
multiPoint = QgsMultiPoint()
multiPoint.addGeometry(QgsPoint(self))
return QgsGeometry(multiPoint)
return QgsGeometry.fromPointXY(self)
#===============================================================================
# fromGeom
#===============================================================================
def fromGeom(self, geom):
"""
la funzione ritorna il punto in forma di QgsGeometry.
"""
return self.set(geom.asPoint())
#============================================================================
# move
#============================================================================
def move(self, offsetX, offsetY):
return self.set(qad_utils.movePoint(self, offsetX, offsetY))
#============================================================================
# rotate
#============================================================================
def rotate(self, basePt, angle):
self.set(qad_utils.rotatePoint(self, basePt, angle))
#============================================================================
# scale
#============================================================================
def scale(self, basePt, scale):
return self.set(qad_utils.scalePoint(self, basePt, scale))
#============================================================================
# mirror
#============================================================================
def mirror(self, mirrorPt, mirrorAngle):
return self.set(qad_utils.mirrorPoint(self, mirrorPt, mirrorAngle))