-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqad_grip.py
816 lines (637 loc) · 32 KB
/
qad_grip.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
classe per gestire i grip
-------------------
begin : 2015-09-29
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 QPointF, QRectF
from qgis.PyQt.QtGui import QPen, QColor, QBrush
from qgis.core import QgsPointXY, QgsWkbTypes, QgsCoordinateTransform, QgsGeometry
from qgis.gui import QgsMapCanvasItem
from .qad_multi_geom import *
from .qad_variables import QadVariables
from .qad_entity import QadEntity, QadEntityTypeEnum
from .qad_dim import QadDimStyles, QadDimComponentEnum
from .qad_msg import QadMsg
#===============================================================================
# QadGripStatusEnum class.
#===============================================================================
class QadGripStatusEnum():
NONE = 0 # nessuno
UNSELECTED = 1 # grip non selezionato
SELECTED = 2 # grip selezionato
HOVER = 3 # grip non selezionati quando il cursore si ferma su di essi
#===============================================================================
# QadGripIconTypeEnum class.
#===============================================================================
class QadGripIconTypeEnum():
NONE = 0 # nessuno
BOX = 1 # un quadrato
CIRCLE = 2 # cerchio
RECTANGLE = 3 # rettangolo
#===============================================================================
# QadGripMarker class.
#===============================================================================
class QadGripMarker(QgsMapCanvasItem):
"""
Classe che gestisce i marcatori dei grip
"""
#============================================================================
# __init__
#============================================================================
def __init__(self, mapCanvas):
QgsMapCanvasItem.__init__(self, mapCanvas)
self.canvas = mapCanvas
self.iconType = QadGripIconTypeEnum.BOX # icon to be shown
self.iconSize = QadVariables.get(QadMsg.translate("Environment variables", "GRIPSIZE"))
self.borderColor = QadVariables.get(QadMsg.translate("Environment variables", "GRIPCONTOUR")) # color of the border
self.center = QgsPointXY(0, 0) # coordinates of the point in the center
self.setGrip(QadGripStatusEnum.UNSELECTED, QadGripIconTypeEnum.BOX)
def __del__(self):
self.removeItem()
def removeItem(self):
self.canvas.scene().removeItem(self)
def setCenter(self, point):
# point è in map coordinates
self.center = point
pt = self.toCanvasCoordinates(self.center)
self.setPos(pt)
def setGrip(self, status, iconType, rot = None):
# rot in radians counterclockwise (0 = horizontal)
if status == QadGripStatusEnum.UNSELECTED:
self.fillColor = QadVariables.get(QadMsg.translate("Environment variables", "GRIPCOLOR"))
elif status == QadGripStatusEnum.SELECTED:
self.fillColor = QadVariables.get(QadMsg.translate("Environment variables", "GRIPHOT"))
elif status == QadGripStatusEnum.HOVER:
self.fillColor = QadVariables.get(QadMsg.translate("Environment variables", "GRIPHOVER"))
self.status = status
self.__iconType = iconType
if rot is not None:
self.__rot = -qad_utils.toDegrees(rot) # trasformo in gradi in senso orario
def paint(self, painter, option, widget):
"""
painter é un QPainter
"""
pen = QPen(QColor(self.borderColor))
pen.setWidth(1)
painter.setPen(pen)
painter.rotate(self.__rot)
if self.__iconType == QadGripIconTypeEnum.NONE:
pass
elif self.__iconType == QadGripIconTypeEnum.BOX:
# un quadrato
painter.fillRect(-self.iconSize, -self.iconSize, self.iconSize * 2, self.iconSize * 2, QBrush(QColor(self.fillColor)));
painter.drawRect(-self.iconSize, -self.iconSize, self.iconSize * 2, self.iconSize * 2)
elif self.__iconType == QadGripIconTypeEnum.CIRCLE:
# cerchio
painter.setBrush(QBrush(QColor(self.fillColor)))
painter.drawEllipse(QPointF(0, 0), self.iconSize, self.iconSize)
elif self.__iconType == QadGripIconTypeEnum.RECTANGLE:
# un rettangolo
painter.fillRect(-self.iconSize, -self.iconSize / 2, self.iconSize * 2, self.iconSize, QBrush(QColor(self.fillColor)));
painter.drawRect(-self.iconSize, -self.iconSize / 2, self.iconSize * 2, self.iconSize)
def boundingRect(self):
if self.__rot != 0:
width = qad_utils.getDistance(QgsPointXY(0,0), QgsPointXY(self.iconSize, self.iconSize))
height = width
else:
width = self.iconSize
height = self.iconSize
return QRectF(-width/2, -height/2, width, height)
def updatePosition(self):
self.setCenter(self.center)
#===============================================================================
# QadGripPointTypeEnum class.
#===============================================================================
class QadGripPointTypeEnum():
NONE = 0 # nessuno
VERTEX = 1 # vertice di una geometria
LINE_MID_POINT = 2 # punto medio di un segmento
CENTER = 3 # centro di un cerchio, di un arco, di un ellisse o di un arco di ellisse
QUA_POINT = 4 # punto quadrante
ARC_MID_POINT = 5 # punto medio di un arco o fi un arco di ellisse
END_VERTEX = 6 # vertice iniziale e finale di una geometria
#===============================================================================
# QadEntityGripPoint class.
#===============================================================================
class QadEntityGripPoint():
"""
Classe che gestisce un punto di grip per una entità
"""
#============================================================================
# __init__
#============================================================================
def __init__(self, mapCanvas, point, type, atGeom = 0, atSubGeom = 0, nVertex = 0, rot = 0.0):
self.atGeom = atGeom # numero di geometria (0-index)
self.atSubGeom = atSubGeom # numero di sotto-geometria (0-index)
self.nVertex = nVertex # numero di vertice della polilinea della geometria e sotto-geometria (0-index)
self.gripType = type
self.gripMarker = QadGripMarker(mapCanvas)
self.gripMarker.setGrip(QadGripStatusEnum.UNSELECTED, self.gripType2IconType(self.gripType), rot)
self.gripMarker.setCenter(point)
def __del__(self):
self.removeItem()
del self.gripMarker
def removeItem(self):
self.gripMarker.removeItem()
def getPoint(self):
return self.gripMarker.center
def isIntersecting(self, point):
# point è in map coordinate
ToleranceInMapUnits = self.gripMarker.iconSize * self.gripMarker.canvas.mapSettings().mapUnitsPerPixel()
if point.x() >= self.getPoint().x() - ToleranceInMapUnits and \
point.x() <= self.getPoint().x() + ToleranceInMapUnits and \
point.y() >= self.getPoint().y() - ToleranceInMapUnits and \
point.y() <= self.getPoint().y() + ToleranceInMapUnits:
return True
else:
return False
def select(self): # seleziona un grip
self.gripMarker.setGrip(QadGripStatusEnum.SELECTED, self.gripType2IconType(self.gripType))
self.gripMarker.show()
def unselect(self): # deseleziona un grip
self.gripMarker.setGrip(QadGripStatusEnum.UNSELECTED, self.gripType2IconType(self.gripType))
self.gripMarker.show()
def hover(self): # grip non selezionato quando il cursore si ferma su di esso
if self.getStatus() == QadGripStatusEnum.UNSELECTED:
self.gripMarker.setGrip(QadGripStatusEnum.HOVER, self.gripType2IconType(self.gripType))
self.gripMarker.show()
def getStatus(self):
return self.gripMarker.status
def gripType2IconType(self, gripType):
if gripType == QadGripPointTypeEnum.VERTEX or gripType == QadGripPointTypeEnum.END_VERTEX:
return QadGripIconTypeEnum.BOX
elif gripType == QadGripPointTypeEnum.LINE_MID_POINT or gripType == QadGripPointTypeEnum.ARC_MID_POINT:
return QadGripIconTypeEnum.RECTANGLE
elif gripType == QadGripPointTypeEnum.CENTER:
return QadGripIconTypeEnum.CIRCLE
elif gripType == QadGripPointTypeEnum.QUA_POINT:
return QadGripIconTypeEnum.BOX
else:
return None
#===============================================================================
# QadEntityGripPoints class.
#===============================================================================
class QadEntityGripPoints(QgsMapCanvasItem):
"""
Classe che gestisce i punti di grip per una entità
"""
#============================================================================
# __init__
#============================================================================
def __init__(self, plugIn, entity = None, grips = 2):
self.plugIn = plugIn
self.mapCanvas = plugIn.canvas
self.gripPoints = [] # lista dei punti di grip in map coordinate
self.iHoverGripPoints = [] # lista delle posizioni in gripPoints del punti hover
# Build the spatial index for faster lookup.
self.index = QgsSpatialIndex()
if entity is not None:
self.entity = QadEntity(entity)
self.gripPoints = self.initGripPoints(grips)
self.index = self.initIndexGripPoints()
def __del__(self):
self.removeItems()
if self.index is not None:
del self.index
def set(self, layer, featureId, grips = 2):
self.entity = QadEntity()
self.entity.set(layer, featureId)
self.gripPoints = self.initGripPoints(grips)
self.index = self.initIndexGripPoints()
def removeItems(self):
for gripPoint in self.gripPoints:
gripPoint.removeItem()
del self.gripPoints[:]
del self.iHoverGripPoints[:]
del self.index
self.index = QgsSpatialIndex()
def selectIntersectingGripPoints(self, point):
# seleziona i grip che intersecano un punto in map coordinate
res = 0
# Get the i-pos of all the features in the index that are within
# the bounding box of the current feature because these are the ones
# that will be touching.
ToleranceInMapUnits = QadVariables.get(QadMsg.translate("Environment variables", "GRIPSIZE")) * self.mapCanvas.mapSettings().mapUnitsPerPixel()
rect = QgsRectangle(point.x() - ToleranceInMapUnits, point.y() - ToleranceInMapUnits, \
point.x() + ToleranceInMapUnits, point.y() + ToleranceInMapUnits)
iList = self.index.intersects(rect)
for i in iList:
self.gripPoints[i].select()
res = res + 1
# for gripPoint in self.gripPoints:
# if gripPoint.isIntersecting(point):
# gripPoint.select()
# res = res + 1
return res
def unselectIntersectingGripPoints(self, point):
# deseleziona i grip che intersecano un punto in map coordinate
res = 0
# Get the i-pos of all the features in the index that are within
# the bounding box of the current feature because these are the ones
# that will be touching.
ToleranceInMapUnits = QadVariables.get(QadMsg.translate("Environment variables", "GRIPSIZE")) * self.mapCanvas.mapSettings().mapUnitsPerPixel()
rect = QgsRectangle(point.x() - ToleranceInMapUnits, point.y() - ToleranceInMapUnits, \
point.x() + ToleranceInMapUnits, point.y() + ToleranceInMapUnits)
iList = self.index.intersects(rect)
for i in iList:
self.gripPoints[i].unselect()
res = res + 1
# for gripPoint in self.gripPoints:
# if gripPoint.isIntersecting(point):
# gripPoint.unselect()
# res = res + 1
return res
def toggleSelectIntersectingGripPoints(self, point):
# seleziona i grip deselezionati e deseleziona i grip selezionati
# che intersecano un punto in map coordinate
# Get the i-pos of all the features in the index that are within
# the bounding box of the current feature because these are the ones
# that will be touching.
ToleranceInMapUnits = QadVariables.get(QadMsg.translate("Environment variables", "GRIPSIZE")) * self.mapCanvas.mapSettings().mapUnitsPerPixel()
rect = QgsRectangle(point.x() - ToleranceInMapUnits, point.y() - ToleranceInMapUnits, \
point.x() + ToleranceInMapUnits, point.y() + ToleranceInMapUnits)
iList = self.index.intersects(rect)
for i in iList:
if self.gripPoints[i].getStatus() == QadGripStatusEnum.SELECTED:
self.gripPoints[i].unselect()
else:
self.gripPoints[i].select()
# for gripPoint in self.gripPoints:
# if gripPoint.isIntersecting(point):
# if gripPoint.getStatus() == QadGripStatusEnum.SELECTED:
# gripPoint.unselect()
# else:
# gripPoint.select()
def hoverIntersectingGripPoints(self, point):
# seleziono in modo hover i grip che intersecano un punto (in map coordinate)
# non selezionati quando il cursore si ferma su di esso
for i in self.iHoverGripPoints:
status = self.gripPoints[i].getStatus()
if status == QadGripStatusEnum.SELECTED:
self.gripPoints[i].select()
else:
self.gripPoints[i].unselect()
# for gripPoint in self.gripPoints:
# status = gripPoint.getStatus()
# if status == QadGripStatusEnum.SELECTED:
# gripPoint.select()
# else:
# gripPoint.unselect()
res = 0
del self.iHoverGripPoints[:]
# Get the i-pos of all the features in the index that are within
# the bounding box of the current feature because these are the ones
# that will be touching.
ToleranceInMapUnits = QadVariables.get(QadMsg.translate("Environment variables", "GRIPSIZE")) * self.mapCanvas.mapSettings().mapUnitsPerPixel()
rect = QgsRectangle(point.x() - ToleranceInMapUnits, point.y() - ToleranceInMapUnits, \
point.x() + ToleranceInMapUnits, point.y() + ToleranceInMapUnits)
iList = self.index.intersects(rect)
for i in iList:
self.gripPoints[i].hover()
self.iHoverGripPoints.append(i)
res = res + 1
# for gripPoint in self.gripPoints:
# if gripPoint.isIntersecting(point):
# gripPoint.hover()
# res = res + 1
# else:
# status = gripPoint.getStatus()
# if status == QadGripStatusEnum.SELECTED:
# gripPoint.select()
# else:
# gripPoint.unselect()
return res
def isIntersecting(self, point):
# ritorna il primo punto di grip (QadEntityGripPoint) che interseca point (in map coordinate)
# Get the i-pos of all the features in the index that are within
# the bounding box of the current feature because these are the ones
# that will be touching.
ToleranceInMapUnits = QadVariables.get(QadMsg.translate("Environment variables", "GRIPSIZE")) * self.mapCanvas.mapSettings().mapUnitsPerPixel()
rect = QgsRectangle(point.x() - ToleranceInMapUnits, point.y() - ToleranceInMapUnits, \
point.x() + ToleranceInMapUnits, point.y() + ToleranceInMapUnits)
iList = self.index.intersects(rect)
for i in iList:
return self.gripPoints[i]
# for gripPoint in self.gripPoints:
# if gripPoint.isIntersecting(point):
# return gripPoint
return None
def getSelectedGripPoints(self):
# restituisce una lista di punti in cui i grip sono selezionati
result = []
for gripPoint in self.gripPoints:
if gripPoint.getStatus() == QadGripStatusEnum.SELECTED:
result.append(gripPoint)
return result
def initGripPoints(self, grips = 2):
# restituisce una lista di QadEntityGripPoint
atGeom = 0
atSubGeom = 0
result = []
g = self.entity.getQadGeom()
if g is None:
return result
# verifico se l'entità appartiene ad uno stile di quotatura
dimEntity = QadDimStyles.getDimEntity(self.entity)
if dimEntity is not None:
return self.getGripPointsFromDimComponent(dimEntity, self.entity)
gType = g.whatIs()
if gType == "POINT":
# converto il punto dal layer coordinate in map coordinates
gp = QadEntityGripPoint(self.mapCanvas, g, QadGripPointTypeEnum.VERTEX)
result.append(gp)
elif gType == "MULTI_POINT":
for atGeom in range(0, g.qty()):
gp = QadEntityGripPoint(self.mapCanvas, g.getPointAt(atGeom), QadGripPointTypeEnum.VERTEX, atGeom)
result.append(gp)
elif gType == "ARC":
result = self.getGripPointsFromQadArc(g, 0, 0, grips)
elif gType == "CIRCLE":
result = self.getGripPointsFromQadCircle(g, 0, 0)
elif gType == "ELLIPSE":
result = self.getGripPointsFromQadEllipse(g, 0, 0)
elif gType == "ELLIPSE_ARC":
result = self.getGripPointsFromQadEllipseArc(g, 0, 0, grips)
elif gType == "LINE":
result = self.getGripPointsFromQadLine(g, 0, 0, grips)
elif gType == "POLYLINE":
result = self.getGripPointsFromPolyline(g, 0, 0, grips)
elif gType == "MULTI_LINEAR_OBJ":
for atGeom in range(0, g.qty()):
subGeom = g.getLinearObjectAt(atGeom)
subGeomType = subGeom.whatIs()
if subGeomType == "ARC":
result.extend(self.getGripPointsFromQadArc(subGeom, atGeom, 0, grips))
elif subGeomType == "CIRCLE":
result.extend(self.getGripPointsFromQadCircle(subGeom, atGeom, 0))
elif subGeomType == "ELLIPSE":
result.extend(self.getGripPointsFromQadEllipse(subGeom, atGeom, 0))
elif subGeomType == "ELLIPSE_ARC":
result.extend(self.getGripPointsFromQadEllipseArc(subGeom, atGeom, 0, grips))
elif subGeomType == "LINE":
result.extend(self.getGripPointsFromQadLine(subGeom, atGeom, 0, grips))
elif subGeomType == "POLYLINE":
result.extend(self.getGripPointsFromPolyline(subGeom, atGeom, 0, grips))
elif gType == "POLYGON":
for atSubGeom in range(0, g.qty()):
closedObj = g.getClosedObjectAt(atSubGeom)
result.extend(self.getGripPointsFromPolyline(closedObj, 0, atSubGeom, grips))
# aggiungo il centroide
gp = QadEntityGripPoint(self.mapCanvas, closedObj.getCentroid(), QadGripPointTypeEnum.CENTER, 0, atSubGeom)
result.append(gp)
elif gType == "MULTI_POLYGON":
for atGeom in range(0, g.qty()):
polygon = g.getPolygonAt(atGeom)
for atSubGeom in range(0, polygon.qty()):
closedObj = polygon.getClosedObjectAt(atSubGeom)
result.extend(self.getGripPointsFromPolyline(closedObj, atGeom, atSubGeom, grips))
# aggiungo il centroide
gp = QadEntityGripPoint(self.mapCanvas, closedObj.getCentroid(), QadGripPointTypeEnum.CENTER, atGeom, atSubGeom)
result.append(gp)
atSubGeom = atSubGeom + 1
atGeom = atGeom + 1
return result
def initIndexGripPoints(self):
# inizializza l'indice spaziale della lista dei punti di grip
index = QgsSpatialIndex()
f = QgsFeature(QgsFields(), 0)
i = 0
for gp in self.gripPoints:
f.setId(i)
f.setGeometry(QgsGeometry.fromPointXY(gp.getPoint()))
index.insertFeature(f)
i = i + 1
return index
def getGripPointsFromPolyline(self, polyline, atGeom = 0, atSubGeom = 0, grips = 2):
"""
Ottiene una lista di punti di grip da una QadPolyline in map coordinate (vertici e punti medi con rotaz)
grips = 1 Displays grips
grips = 2 Displays additional midpoint grips on polyline segments
"""
result = []
isClosed = polyline.isClosed()
nVertex = 0
while nVertex < polyline.qty():
linearObject = polyline.getLinearObjectAt(nVertex)
startPt = linearObject.getStartPt()
if isClosed == False and nVertex == 0:
gp = QadEntityGripPoint(self.mapCanvas, startPt, QadGripPointTypeEnum.END_VERTEX, atGeom, atSubGeom, nVertex)
else:
gp = QadEntityGripPoint(self.mapCanvas, startPt, QadGripPointTypeEnum.VERTEX, atGeom, atSubGeom, nVertex)
result.append(gp)
if grips == 2: # Displays additional midpoint grips on polyline segments
middlePt = linearObject.getMiddlePt()
rot = linearObject.getTanDirectionOnPt(middlePt)
linearObjectType = linearObject.whatIs()
if linearObjectType == "LINE":
gp = QadEntityGripPoint(self.mapCanvas, middlePt, QadGripPointTypeEnum.LINE_MID_POINT, atGeom, atSubGeom, nVertex, rot)
elif linearObjectType == "ARC" or linearObjectType == "ELLIPSE_ARC":
gp = QadEntityGripPoint(self.mapCanvas, middlePt, QadGripPointTypeEnum.ARC_MID_POINT, atGeom, atSubGeom, nVertex, rot)
result.append(gp)
nVertex = nVertex + 1
# solo se la polilinea è aperta
if isClosed == False:
linearObject = polyline.getLinearObjectAt(-1) # ultima parte
endPt = linearObject.getEndPt()
gp = QadEntityGripPoint(self.mapCanvas, endPt, QadGripPointTypeEnum.END_VERTEX, atGeom, atSubGeom, nVertex)
result.append(gp)
return result
def getGripPointsFromQadLine(self, line, atGeom = 0, atSubGeom = 0, grips = 2):
"""
Ottiene una lista di punti di grip da un QadLine in map coordinate (iniziale, finale, medio)
"""
result = []
startPt = line.getStartPt()
gp = QadEntityGripPoint(self.mapCanvas, startPt, QadGripPointTypeEnum.END_VERTEX, atGeom, atSubGeom, 0)
result.append(gp)
if grips == 2: # Displays additional midpoint grips on polyline segments
middlePt = line.getMiddlePt()
rot = line.getTanDirectionOnMiddlePt()
gp = QadEntityGripPoint(self.mapCanvas, middlePt, QadGripPointTypeEnum.LINE_MID_POINT, atGeom, atSubGeom, 0, rot)
result.append(gp)
endPt = line.getEndPt()
gp = QadEntityGripPoint(self.mapCanvas, endPt, QadGripPointTypeEnum.END_VERTEX, atGeom, atSubGeom, 1)
result.append(gp)
return result
def getGripPointsFromQadCircle(self, circle, atGeom = 0, atSubGeom = 0):
"""
Ottiene una lista di punti di grip da un QadCircle in map coordinate (centro e punti quadrante)
"""
result = []
gp = QadEntityGripPoint(self.mapCanvas, circle.center, QadGripPointTypeEnum.CENTER, atGeom, atSubGeom, -1)
result.append(gp)
qua_points = circle.getQuadrantPoints()
for pt in qua_points:
gp = QadEntityGripPoint(self.mapCanvas, pt, QadGripPointTypeEnum.QUA_POINT, atGeom, atSubGeom, -1)
result.append(gp)
return result
def getGripPointsFromQadEllipse(self, ellipse, atGeom = 0, atSubGeom = 0):
"""
Ottiene una lista di punti di grip da un QadEllipse in map coordinate (centro e punti quadrante)
"""
result = []
gp = QadEntityGripPoint(self.mapCanvas, ellipse.center, QadGripPointTypeEnum.CENTER, atGeom, atSubGeom, -1)
result.append(gp)
qua_points = ellipse.getQuadrantPoints()
for pt in qua_points:
gp = QadEntityGripPoint(self.mapCanvas, pt, QadGripPointTypeEnum.QUA_POINT, atGeom, atSubGeom, -1)
result.append(gp)
return result
def getGripPointsFromQadArc(self, arc, atGeom = 0, atSubGeom = 0, grips = 2):
"""
Ottiene una lista di punti di grip da un QadArc in map coordinate (punto centrale, iniziale, finale, medio)
"""
result = []
gp = QadEntityGripPoint(self.mapCanvas, arc.center, QadGripPointTypeEnum.CENTER, atGeom, atSubGeom, -1)
result.append(gp)
startPt = arc.getStartPt()
gp = QadEntityGripPoint(self.mapCanvas, startPt, QadGripPointTypeEnum.END_VERTEX, atGeom, atSubGeom, 0)
result.append(gp)
endPt = arc.getEndPt()
gp = QadEntityGripPoint(self.mapCanvas, endPt, QadGripPointTypeEnum.END_VERTEX, atGeom, atSubGeom, 1)
result.append(gp)
if grips == 2: # Displays additional midpoint grips on polyline segments
middlePt = arc.getMiddlePt()
rot = arc.getTanDirectionOnMiddlePt()
gp = QadEntityGripPoint(self.mapCanvas, middlePt, QadGripPointTypeEnum.ARC_MID_POINT, atGeom, atSubGeom, 0, rot)
result.append(gp)
return result
def getGripPointsFromQadEllipseArc(self, ellipseArc, atGeom = 0, atSubGeom = 0, grips = 2):
"""
Ottiene una lista di punti di grip da un QadEllipseArc in map coordinate (punto centrale, iniziale, finale e punti quadrante)
"""
result = []
gp = QadEntityGripPoint(self.mapCanvas, ellipseArc.center, QadGripPointTypeEnum.CENTER, atGeom, atSubGeom, -1)
result.append(gp)
startPt = ellipseArc.getStartPt()
gp = QadEntityGripPoint(self.mapCanvas, startPt, QadGripPointTypeEnum.END_VERTEX, atGeom, atSubGeom, 0)
result.append(gp)
endPt = ellipseArc.getEndPt()
gp = QadEntityGripPoint(self.mapCanvas, endPt, QadGripPointTypeEnum.END_VERTEX, atGeom, atSubGeom, 1)
result.append(gp)
qua_points = ellipseArc.getQuadrantPoints()
for pt in qua_points:
if pt is not None:
gp = QadEntityGripPoint(self.mapCanvas, pt, QadGripPointTypeEnum.QUA_POINT, atGeom, atSubGeom, -1)
result.append(gp)
return result
def getGripPointsFromDimComponent(self, dimEntity, component):
"""
Ottiene una lista di punti di grip del componente di una quotatura
component = QadEntity
"""
result = []
dimComponent = dimEntity.getDimComponentByEntity(component)
if dimComponent is None: return result
if dimComponent == QadDimComponentEnum.TEXT_PT or \
dimComponent == QadDimComponentEnum.DIM_PT1 or \
dimComponent == QadDimComponentEnum.DIM_PT2:
g = component.getQadGeom()
gType = g.whatIs()
if gType == "POINT":
gp = QadEntityGripPoint(self.mapCanvas, g, QadGripPointTypeEnum.VERTEX)
result.append(gp)
return result
#===============================================================================
# QadEntitySetGripPoints class.
#===============================================================================
class QadEntitySetGripPoints(QgsMapCanvasItem):
"""
Classe che gestisce i punti di grip per una gruppo di selezione di entità
"""
#============================================================================
# __init__
#============================================================================
def __init__(self, plugIn):
self.plugIn = plugIn
self.mapCanvas = plugIn.canvas
self.entityGripPoints = []
def __del__(self):
self.removeItems()
def removeItems(self):
for entityGripPoint in self.entityGripPoints:
entityGripPoint.removeItems()
del self.entityGripPoints[:]
def set(self, entitySet, grips = 2):
"""
grips = 0 Hides grips
grips = 1 Displays grips
grips = 2 Displays additional midpoint grips on polyline segments
"""
self.removeItems()
if grips == 0: # nasconde i grip
return
# for each layer
for layerEntitySet in entitySet.layerEntitySetList:
for featureId in layerEntitySet.featureIds:
entityGripPoints = QadEntityGripPoints(self.plugIn)
entityGripPoints.set(layerEntitySet.layer, featureId, grips)
self.entityGripPoints.append(entityGripPoints)
def addEntity(self, entity, grips = 2):
"""
grips = 0 Hides grips
grips = 1 Displays grips
grips = 2 Displays additional midpoint grips on polyline segments
"""
if grips == 0: # nasconde i grip
return
if self.containsEntity(entity) == False:
entityGripPoints = QadEntityGripPoints(self.plugIn)
entityGripPoints.set(entity.layer, entity.featureId, grips)
self.entityGripPoints.append(entityGripPoints)
def hoverIntersectingGripPoints(self, point):
res = 0
for entityGripPoint in self.entityGripPoints:
res = res + entityGripPoint.hoverIntersectingGripPoints(point)
return res
def selectIntersectingGripPoints(self, point):
res = 0
for entityGripPoint in self.entityGripPoints:
res = res + entityGripPoint.selectIntersectingGripPoints(point)
return res
def unselectIntersectingGripPoints(self, point):
res = 0
for entityGripPoint in self.entityGripPoints:
res = res + entityGripPoint.unselectIntersectingGripPoints(point)
return res
def toggleSelectIntersectingGripPoints(self, point):
for entityGripPoint in self.entityGripPoints:
entityGripPoint.toggleSelectIntersectingGripPoints(point)
def isIntersecting(self, point):
# ritorna 2 valori: QadEntityGripPoints, QadEntityGripPoint
for entityGripPoints in self.entityGripPoints:
res = entityGripPoints.isIntersecting(point)
if res is not None:
return entityGripPoints, res
return None, None
def getSelectedEntityGripPoints(self):
# ritorna una lista delle entityGripPoint con dei grip point selezionati
# la funzione non fa copie delle entityGripPoint
result = []
for entityGripPoint in self.entityGripPoints:
for gripPoint in entityGripPoint.gripPoints:
if gripPoint.getStatus() == QadGripStatusEnum.SELECTED:
result.append(entityGripPoint)
return result
def containsEntity(self, entity):
for entityGripPoint in self.entityGripPoints:
if entityGripPoint.entity == entity:
return True
return False
def count(self):
return len(self.entityGripPoints)