forked from geosim/QAD
-
Notifications
You must be signed in to change notification settings - Fork 13
/
qad_vertexmarker.py
290 lines (254 loc) · 11.7 KB
/
qad_vertexmarker.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
classe per gestire i simboli marcatori
-------------------
begin : 2013-05-22
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 *
from .qad_msg import QadMsg
from .qad_variables import QadVariables
#===============================================================================
# QadVertexmarkerIconTypeEnum class.
#===============================================================================
class QadVertexmarkerIconTypeEnum():
NONE = 0 # nessuno
CROSS = 1 # croce
X = 2 # una X
BOX = 3 # un quadrato
TRIANGLE = 4 # triangolo equilatero con punta in su
CIRCLE = 5 # cerchio
CIRCLE_X = 6 # cerchio con al centro una x
RHOMBUS = 7 # rombo
INFINITY_LINE = 8 # linea infinita (------ . .)
DOUBLE_BOX = 9 # due quadrati sfalsati
PERP = 10 # simbolo di "perpendicolare"
TANGENT = 11 # un cerchio con una retta tangente sopra
DOUBLE_TRIANGLE = 12 # due triangoli uno sull'altro con vertice al centro (clessidra)
BOX_X = 13 # quadrato con al centro una x
PARALLEL = 14 # due righe parallele a 45 gradi
PROGRESS = 15 # linea con X e i puntini (----X-- . .)
X_INFINITY_LINE = 16 # X e i puntini (X-- . .)
PERP_DEFERRED = 17 # come perpendicolare con i puntini
TANGENT_DEFERRED = 18 # come tangente con i puntini
class QadVertexMarker(QgsMapCanvasItem):
"""
Classe che gestisce i marcatori dei vertici
"""
#============================================================================
# __init__
#============================================================================
def __init__(self, mapCanvas):
QgsMapCanvasItem.__init__(self, mapCanvas)
self.__canvas = mapCanvas
self.__iconType = QadVertexmarkerIconTypeEnum.X # icon to be shown
self.__iconSize = QadVariables.get(QadMsg.translate("Environment variables", "AUTOSNAPSIZE"))
self.__center = QgsPointXY(0, 0) # coordinates of the point in the center
self.__color = QColor(255, 0, 0) # color of the marker
self.__penWidth = 2 # pen width
def __del__(self):
self.removeItem()
def removeItem(self):
self.__canvas.scene().removeItem(self)
def setCenter(self, point):
self.__center = point
pt = self.toCanvasCoordinates(self.__center)
self.setPos(pt)
def setIconType(self, iconType):
self.__iconType = iconType
def setIconSize(self, iconSize):
self.__iconSize = iconSize
def setColor(self, color):
self.__color = color
def setPenWidth(self, width):
self.__penWidth = width
def paint(self, painter, option, widget):
"""
p é un QPainter
"""
s = self.__iconSize
pen = QPen(self.__color)
pen.setWidth(self.__penWidth)
painter.setPen(pen)
if self.__iconType == QadVertexmarkerIconTypeEnum.NONE:
pass
elif self.__iconType == QadVertexmarkerIconTypeEnum.CROSS:
# croce
painter.drawLine(QLineF(-s, 0, s, 0))
painter.drawLine(QLineF( 0, -s, 0, s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.X:
# una X
painter.drawLine(QLineF(-s, -s, s, s))
painter.drawLine(QLineF(-s, s, s, -s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.BOX:
# un quadrato
painter.drawLine(QLineF(-s, -s, s, -s))
painter.drawLine(QLineF( s, -s, s, s))
painter.drawLine(QLineF( s, s, -s, s))
painter.drawLine(QLineF(-s, s, -s, -s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.TRIANGLE:
# triangolo equilatero con punta in su
painter.drawLine(QLineF(-s, s, s, s))
painter.drawLine(QLineF( s, s, 0, -s))
painter.drawLine(QLineF( 0, -s, -s, s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.CIRCLE:
# cerchio
# la linea é più sottile
pen.setWidth(self.__penWidth / 2)
painter.setPen(pen)
painter.drawEllipse(QPointF(0, 0), s, s)
pen.setWidth(self.__penWidth)
painter.setPen(pen)
elif self.__iconType == QadVertexmarkerIconTypeEnum.CIRCLE_X:
# cerchio con al centro una x
# la linea é più sottile
pen.setWidth(self.__penWidth / 2)
painter.setPen(pen)
painter.drawEllipse(QPointF(0, 0), s, s)
painter.drawLine(QLineF(-s, -s, s, s))
painter.drawLine(QLineF(-s, s, s, -s))
pen.setWidth(self.__penWidth)
painter.setPen(pen)
elif self.__iconType == QadVertexmarkerIconTypeEnum.RHOMBUS:
# rombo
painter.drawLine(QLineF( 0, -s, -s, 0))
painter.drawLine(QLineF(-s, 0, 0, s))
painter.drawLine(QLineF( 0, s, s, 0))
painter.drawLine(QLineF( s, 0, 0, -s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.INFINITY_LINE:
# linea infinita (------ . .)
l = self.__penWidth
painter.drawLine(QLineF(-s, 0, 0, 0))
painter.drawLine(QLineF(2 * l, 0, 2 * l, 0))
painter.drawLine(QLineF(4 * l, 0, 4 * l, 0))
elif self.__iconType == QadVertexmarkerIconTypeEnum.DOUBLE_BOX:
# due quadrati sfalsati
l = (s / 4)
painter.drawLine(QLineF(-s, -s, -s, l))
painter.drawLine(QLineF(-s, l, -l, l))
painter.drawLine(QLineF(-l, l, -l, s))
painter.drawLine(QLineF(-l, s, s, s))
painter.drawLine(QLineF( s, s, s, -l))
painter.drawLine(QLineF( s, -l, l, -l))
painter.drawLine(QLineF( l, -l, l, -s))
painter.drawLine(QLineF( l, -s, -s, -s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.PERP:
# simbolo di "perpendicolare"
painter.drawLine(QLineF(-s, -s, -s, s))
painter.drawLine(QLineF(-s, s, s, s))
painter.drawLine(QLineF(-s, 0, 0, 0))
painter.drawLine(QLineF( 0, 0, 0, s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.TANGENT:
# un cerchio con una retta tangente sopra
# la linea é più sottile
l = s - self.__penWidth
pen.setWidth(self.__penWidth / 2)
painter.setPen(pen)
painter.drawEllipse(QPointF(0, 0), l + 1, l + 1)
pen.setWidth(self.__penWidth)
painter.setPen(pen)
painter.drawLine(QLineF(-s, -s, s, -s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.DOUBLE_TRIANGLE:
# due triangoli uno sull'altro con vertice al centro (clessidra)
# le linee oblique sono più sottili
pen.setWidth(self.__penWidth / 2)
painter.setPen(pen)
painter.drawLine(QLineF(-s, -s, s, s))
painter.drawLine(QLineF( s, -s, -s, s))
pen.setWidth(self.__penWidth)
painter.setPen(pen)
painter.drawLine(QLineF(-s, -s, s, -s))
painter.drawLine(QLineF(-s, s, s, s))
elif self.__iconType == QadVertexmarkerIconTypeEnum.BOX_X:
# quadrato con al centro una x
painter.drawLine(QLineF(-s, -s, s, -s))
painter.drawLine(QLineF( s, -s, s, s))
painter.drawLine(QLineF( s, s, -s, s))
painter.drawLine(QLineF(-s, s, -s, -s))
# le linee oblique della x sono più sottili
pen.setWidth(self.__penWidth / 2)
painter.setPen(pen)
painter.drawLine(QLineF(-s, -s, s, s))
painter.drawLine(QLineF(-s, s, s, -s))
pen.setWidth(self.__penWidth)
painter.setPen(pen)
elif self.__iconType == QadVertexmarkerIconTypeEnum.PARALLEL:
# due righe parallele a 45 gradi
painter.drawLine(QLineF(-s, 0, 0, -s))
painter.drawLine(QLineF( 0, s, s, 0))
elif self.__iconType == QadVertexmarkerIconTypeEnum.PROGRESS:
# linea con X e i puntini (----X-- . .)
l = self.__penWidth
painter.drawLine(QLineF(-s, 0, 0, 0))
painter.drawLine(QLineF(2 * l, 0, 2 * l, 0))
painter.drawLine(QLineF(4 * l, 0, 4 * l, 0))
# le linee oblique della x sono più sottili
pen.setWidth(self.__penWidth / 2)
l = s / 2
painter.setPen(pen)
painter.drawLine(QLineF(-l, -l, l, l))
painter.drawLine(QLineF(-l, l, l, -l))
pen.setWidth(self.__penWidth)
painter.setPen(pen)
elif self.__iconType == QadVertexmarkerIconTypeEnum.X_INFINITY_LINE:
# linea con X e i puntini (X-- . .)
l = self.__penWidth
painter.drawLine(QLineF(2 * l, 0, 2 * l, 0))
painter.drawLine(QLineF(4 * l, 0, 4 * l, 0))
# le linee oblique della x sono più sottili
pen.setWidth(self.__penWidth / 2)
l = s / 2
painter.setPen(pen)
painter.drawLine(QLineF(-l, -l, l, l))
painter.drawLine(QLineF(-l, l, l, -l))
pen.setWidth(self.__penWidth)
painter.setPen(pen)
elif self.__iconType == QadVertexmarkerIconTypeEnum.PERP_DEFERRED:
painter.drawLine(QLineF(-s, -s, -s, s))
painter.drawLine(QLineF(-s, s, s, s))
painter.drawLine(QLineF(-s, 0, 0, 0))
painter.drawLine(QLineF( 0, 0, 0, s))
# simbolo di "perpendicolare" con i puntini
l = s - self.__penWidth
l = l + (self.__penWidth * 2)
painter.drawLine(QLineF(l, 0, l, 0))
l = l + (self.__penWidth * 2)
painter.drawLine(QLineF(l, 0, l, 0))
elif self.__iconType == QadVertexmarkerIconTypeEnum.TANGENT_DEFERRED:
# un cerchio con una retta tangente sopra
# la linea é più sottile
l = s - self.__penWidth
pen.setWidth(self.__penWidth / 2)
painter.setPen(pen)
painter.drawEllipse(QPointF(0, 0), l + 1, l + 1)
pen.setWidth(self.__penWidth)
painter.setPen(pen)
painter.drawLine(QLineF(-s, -s, s, -s))
# come tangente con i puntini
l = l + (self.__penWidth * 2)
painter.drawLine(QLineF(l, 0, l, 0))
l = l + (self.__penWidth * 2)
painter.drawLine(QLineF(l, 0, l, 0))
def boundingRect(self):
a = self.__iconSize / 2.0 + 1
width = 2 * a + self.__penWidth * 2
height = 2 * a
return QRectF(-a, -a, width, height)
def updatePosition(self):
self.setCenter(self.__center)