forked from geosim/QAD
-
Notifications
You must be signed in to change notification settings - Fork 13
/
qad_maptool.py
946 lines (785 loc) · 42.8 KB
/
qad_maptool.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
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
map tool per lo stato di quiete
-------------------
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.core import QgsMapLayer, QgsPointXY
from qgis.gui import QgsMapTool
from qgis.PyQt.QtCore import Qt, QTimer, QPoint, QEvent
from qgis.PyQt.QtGui import QCursor, QKeyEvent
from qgis.PyQt.QtWidgets import QAction, QMenu
import datetime
from . import qad_utils
from .qad_variables import QadVariables
from .qad_rubberband import QadCursorRubberBand, QadCursorTypeEnum
from .qad_getpoint import QadGetPointDrawModeEnum
from .qad_entity import QadEntitySet, QadEntity
from .qad_grip import QadEntitySetGripPoints, QadGripStatusEnum
from .qad_dynamicinput import QadDynamicCmdInput, QadDynamicInputContextEnum
from .cmd.qad_generic_cmd import QadCommandClass
from .cmd.qad_ssget_cmd import QadSSGetClass
from .cmd.qad_arc_cmd import QadGRIPCHANGEARCRADIUSCommandClass
from .cmd.qad_generic_cmd import QadCommandClass
from .cmd.qad_lengthen_cmd import QadGRIPLENGTHENCommandClass
from .cmd.qad_mirror_cmd import QadGRIPMIRRORCommandClass
from .cmd.qad_move_cmd import QadGRIPMOVECommandClass
from .cmd.qad_pedit_cmd import QadGRIPINSERTREMOVEVERTEXCommandClass, QadGRIPARCLINECONVERTCommandClass
from .cmd.qad_rotate_cmd import QadGRIPROTATECommandClass
from .cmd.qad_scale_cmd import QadGRIPSCALECommandClass
from .cmd.qad_ssget_cmd import QadSSGetClass
from .cmd.qad_stretch_cmd import QadGRIPSTRETCHCommandClass
from .qad_dim import QadDimStyles
from .qad_msg import QadMsg
# Main Map Tool class.
class QadMapTool(QgsMapTool):
def __init__(self, plugIn):
QgsMapTool.__init__(self, plugIn.iface.mapCanvas())
self.plugIn = plugIn
self.iface = self.plugIn.iface
self.canvas = self.plugIn.iface.mapCanvas()
self.cursor = QCursor(Qt.BlankCursor)
self.__csrRubberBand = QadCursorRubberBand(self.canvas, QadCursorTypeEnum.BOX | QadCursorTypeEnum.CROSS)
self.entitySet = QadEntitySet()
self.entitySetGripPoints = QadEntitySetGripPoints(plugIn)
self.gripPopupMenu = None
self.timerForGripMenu = QTimer()
self.timerForGripMenu.setSingleShot(True)
self.startDateTimeForRightClick = 0
# input dinamico
self.dynamicCmdInput = QadDynamicCmdInput(plugIn)
def __del__(self):
self.removeItems()
def removeItems(self):
if self.__csrRubberBand is not None:
self.__csrRubberBand.removeItems() # prima lo stacco dal canvas altrimenti non si rimuove perchè usato da canvas
del self.__csrRubberBand
__csrRubberBand = None
self.entitySet.clear()
self.entitySetGripPoints.removeItems()
if self.dynamicCmdInput is not None:
self.dynamicCmdInput.removeItems()
del self.dynamicCmdInput
self.dynamicCmdInput = None
#============================================================================
# getDynamicInput
#============================================================================
def getDynamicInput(self):
return self.dynamicCmdInput
#============================================================================
# UpdatedVariablesEvent
#============================================================================
def UpdatedVariablesEvent(self):
# aggiorna in base alle nuove impostazioni delle variabili
self.removeItems()
self.__csrRubberBand = QadCursorRubberBand(self.canvas, QadCursorTypeEnum.BOX | QadCursorTypeEnum.CROSS)
if self.dynamicCmdInput is not None:
del self.dynamicCmdInput
self.dynamicCmdInput = QadDynamicCmdInput(self.plugIn)
#============================================================================
# clearEntitySet
#============================================================================
def clearEntitySet(self):
self.entitySet.deselectOnLayer()
self.entitySet.clear()
#============================================================================
# clearEntityGripPoints
#============================================================================
def clearEntityGripPoints(self):
self.entitySetGripPoints.removeItems() # svuoto la lista
#============================================================================
# refreshEntityGripPoints
#============================================================================
def refreshEntityGripPoints(self, entitySet = None):
if entitySet is None:
entitySet = self.entitySet
gripObjLimit = QadVariables.get(QadMsg.translate("Environment variables", "GRIPOBJLIMIT"))
if gripObjLimit != 0: # When set to 0, grips are always displayed.
if entitySet.count() > gripObjLimit:
# Suppresses the display of grips when the selection set includes more than the specified number of objects
self.clearEntityGripPoints()
return
# cancello i grip delle entità che non sono in entitySet o che non sono in layer vettoriali modificabili
i = self.entitySetGripPoints.count() - 1
while i >= 0:
entityGripPoint = self.entitySetGripPoints.entityGripPoints[i]
if entitySet.containsEntity(entityGripPoint.entity) == False or \
entityGripPoint.entity.layer.type() != QgsMapLayer.VectorLayer or entityGripPoint.entity.layer.isEditable() == False:
self.entitySetGripPoints.entityGripPoints[i].removeItems() # lo stacco dal canvas
del self.entitySetGripPoints.entityGripPoints[i]
i = i - 1
entity = QadEntity()
for layerEntitySet in entitySet.layerEntitySetList:
# considero solo i layer vettoriali che sono modificabili
layer = layerEntitySet.layer
if layer.type() == QgsMapLayer.VectorLayer and layer.isEditable():
for featureId in layerEntitySet.featureIds:
entity.set(layer, featureId)
self.entitySetGripPoints.addEntity(entity, QadVariables.get(QadMsg.translate("Environment variables", "GRIPS")))
#============================================================================
# INIZIO - eventi per il mouse
#============================================================================
#============================================================================
# canvasPressEvent
#============================================================================
def canvasPressEvent(self, event):
if event.button() == Qt.RightButton:
self.startDateTimeForRightClick = datetime.datetime.now()
elif event.button() == Qt.LeftButton:
# verifico se tasto shift premuto
shiftKey = True if event.modifiers() & Qt.ShiftModifier else False
# posizione corrente del mouse
point = self.toMapCoordinates(event.pos())
# leggo il punto grip che si interseca alla posizione del mouse
entityGripPoints, entityGripPoint = self.entitySetGripPoints.isIntersecting(point)
if entityGripPoint is not None:
if shiftKey == False: # lancio il comando
selectedEntityGripPoints = self.entitySetGripPoints.getSelectedEntityGripPoints()
# se non ci sono già grip selezionati
if len(selectedEntityGripPoints) == 0:
# seleziono il corrente
if self.entitySetGripPoints.selectIntersectingGripPoints(point) > 0:
selectedEntityGripPoints = self.entitySetGripPoints.getSelectedEntityGripPoints()
# lancio il comando
self.plugIn.runCommand("QadVirtualGripCommandsClass", [QadVirtualGripCommandsEnum.STRECTH, \
self.entitySetGripPoints, entityGripPoint.getPoint()])
else: # shift premuto
# inverto lo stato ai grip che intersecano il punto
self.entitySetGripPoints.toggleSelectIntersectingGripPoints(point)
else:
result = qad_utils.getEntSel(event.pos(), self, \
QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")))
if result is not None:
feature = result[0]
layer = result[1]
tmpEntity = QadEntity()
tmpEntity.set(layer, feature.id())
SSGetClass = QadSSGetClass(self.plugIn)
SSGetClass.entitySet.set(self.entitySet)
SSGetClass.elaborateEntity(tmpEntity, shiftKey)
self.plugIn.showMsg("\n", True) # ripete il prompt
self.entitySet.set(SSGetClass.entitySet)
del SSGetClass # che deseleziona gli oggetti
self.entitySet.selectOnLayer(False)
self.refreshEntityGripPoints(self.entitySet)
else:
self.plugIn.runCommand("QadVirtualSelCommandClass", point)
#============================================================================
# canvasDoubleClickEvent
#============================================================================
def canvasDoubleClickEvent(self,event):
pass
#============================================================================
# canvasMoveEvent
#============================================================================
def canvasMoveEvent(self, event):
self.timerForGripMenu.stop()
point = self.toMapCoordinates(event.pos())
self.__csrRubberBand.moveEvent(point)
if self.dynamicCmdInput.prevPart is not None or self.dynamicCmdInput.nextPart is not None:
changedPart = True
else:
changedPart = False
self.dynamicCmdInput.setPrevPart(None)
self.dynamicCmdInput.setNextPart(None)
# hover grip points
if self.entitySetGripPoints.hoverIntersectingGripPoints(point) == 1:
for entityGripPoint in self.entitySetGripPoints.entityGripPoints:
for gripPoint in entityGripPoint.gripPoints:
if gripPoint.isIntersecting(point) and gripPoint.getStatus() == QadGripStatusEnum.HOVER:
self.dynamicCmdInput.setPrevNextPart(entityGripPoint.entity, gripPoint)
self.dynamicCmdInput.show(True, self.canvas.mouseLastXY())
# Specifica i metodi di accesso per le opzioni dei grip multifunzionali.
# se > 1 devono essere mostrati i menu dinamici
if QadVariables.get(QadMsg.translate("Environment variables", "GRIPMULTIFUNCTIONAL")) > 1:
pos = QPoint(event.pos().x(), event.pos().y())
shot = lambda: self.displayPopupMenuOnGrip(pos, entityGripPoint.entity, gripPoint)
del self.timerForGripMenu
self.timerForGripMenu = QTimer()
self.timerForGripMenu.setSingleShot(True)
self.timerForGripMenu.timeout.connect(shot)
self.timerForGripMenu.start(1000) # 1 sec tempo per il grip
return
else:
if changedPart == True:
self.dynamicCmdInput.show(True, self.canvas.mouseLastXY())
else:
self.dynamicCmdInput.mouseMoveEvent(event.pos())
#============================================================================
# canvasReleaseEvent
#============================================================================
def canvasReleaseEvent(self, event):
if event.button() == Qt.RightButton:
shortCutMenu = QadVariables.get(QadMsg.translate("Environment variables", "SHORTCUTMENU"))
if shortCutMenu == 0:
# equivale a premere INVIO
return self.plugIn.showEvaluateMsg(None)
else:
if self.entitySet.count() == 0: # nessun oggetto selezionato (modalità Default)
# 16 = Enables the display of a shortcut menu when the right button on the pointing device is held down long enough
if shortCutMenu & 16:
now = datetime.datetime.now()
value = QadVariables.get(QadMsg.translate("Environment variables", "SHORTCUTMENUDURATION"))
shortCutMenuDuration = datetime.timedelta(0, 0, 0, value)
# se supera il numero di millisecondi impostato da SHORTCUTMENUDURATION
if now - self.startDateTimeForRightClick > shortCutMenuDuration:
return self.displayPopupMenuOnQuiescentState(event.pos())
else:
# se click veloce equivale a premere INVIO
return self.plugIn.showEvaluateMsg(None)
else:
# 1 = Enables Default mode shortcut menus
if shortCutMenu & 1:
return self.displayPopupMenuOnQuiescentState(event.pos())
else:
# equivale a premere INVIO
return self.plugIn.showEvaluateMsg(None)
else: # ci sono degli oggetti selezionati
# 2 = Enables Edit mode shortcut menus
if shortCutMenu & 2:
return self.displayPopupMenuOnQuiescentState(event.pos())
else:
# equivale a premere INVIO
return self.plugIn.showEvaluateMsg(None)
#============================================================================
# FINE - eventi per il mouse
# INIZIO - eventi per la tastiera
#============================================================================
#============================================================================
# keyPressEvent
#============================================================================
def keyPressEvent(self, e):
myEvent = e
if self.plugIn.shortCutManagement(myEvent): # se è stata gestita una sequenza di tasti scorciatoia
return
if myEvent.text() != "" and self.dynamicCmdInput.show(True, self.canvas.mouseLastXY(), self.dynamicCmdInput.getPrompt()) == True:
self.dynamicCmdInput.keyPressEvent(myEvent)
else:
self.plugIn.keyPressEvent(myEvent)
#============================================================================
# FINE - eventi per la tastiera
# INIZIO - eventi per la rotella
#============================================================================
#============================================================================
# wheelEvent
#============================================================================
def wheelEvent(self, event):
QgsMapTool.wheelEvent(self, event)
self.__csrRubberBand.moveEvent(self.toMapCoordinates(event.pos()))
#============================================================================
# FINE - eventi per la rotella
#============================================================================
#============================================================================
# activate
#============================================================================
def activate(self):
self.canvas.setToolTip("")
self.canvas.setCursor(self.cursor)
# posizione corrente del mouse
self.__csrRubberBand.moveEvent(self.toMapCoordinates(self.canvas.mouseLastXY()))
self.__csrRubberBand.show()
self.entitySet.initByCurrentQgsSelectedFeatures(qad_utils.getVisibleVectorLayers(self.canvas)) # Tutti i layer vettoriali visibili
self.refreshEntityGripPoints(self.entitySet)
self.plugIn.QadCommands.continueCommandFromMapTool()
self.plugIn.disableShortcut()
self.dynamicCmdInput.setPrevPart(None)
self.dynamicCmdInput.setNextPart(None)
self.dynamicCmdInput.show(True, self.canvas.mouseLastXY())
#============================================================================
# deactivate
#============================================================================
def deactivate(self):
self.__csrRubberBand.hide()
self.timerForGripMenu.stop()
self.plugIn.enableShortcut()
self.dynamicCmdInput.show(False)
#============================================================================
# isTransient
#============================================================================
def isTransient(self):
return False # questo tool non fa zoom o pan
#============================================================================
# isEditTool
#============================================================================
def isEditTool(self):
return False # questo tool non fa editing
#============================================================================
# displayPopupMenuOnQuiescentState
#============================================================================
def displayPopupMenuOnQuiescentState(self, pos):
popupMenu = QMenu(self.canvas)
history = self.plugIn.cmdsHistory
isLastCmdToInsert = True
isRecentMenuToInsert = True
historyLen = len(history)
i = historyLen - 1
cmdInputHistoryMax = QadVariables.get(QadMsg.translate("Environment variables", "CMDINPUTHISTORYMAX"))
while i >= 0 and (historyLen - i) <= cmdInputHistoryMax:
cmdName = history[i]
i = i - 1
cmd = self.plugIn.QadCommands.getCommandObj(cmdName)
if cmd is not None:
if isLastCmdToInsert:
isLastCmdToInsert = False
msg = QadMsg.translate("Popup_menu_graph_window", "Repeat ") + cmd.getName()
icon = cmd.getIcon()
if icon is None:
lastCmdAction = QAction(msg, popupMenu)
else:
lastCmdAction = QAction(icon, msg, popupMenu)
cmd.connectQAction(lastCmdAction)
popupMenu.addAction(lastCmdAction)
else:
if isRecentMenuToInsert:
isRecentMenuToInsert = False
recentCmdsMenu = popupMenu.addMenu(QadMsg.translate("Popup_menu_graph_window", "Recent commands"))
icon = cmd.getIcon()
if icon is None:
recentCmdAction = QAction(cmd.getName(), recentCmdsMenu)
else:
recentCmdAction = QAction(icon, cmd.getName(), recentCmdsMenu)
cmd.connectQAction(recentCmdAction)
recentCmdsMenu.addAction(recentCmdAction)
if isLastCmdToInsert == False: # menu non vuoto
popupMenu.addSeparator()
# aggiungo comando "OPTIONS"
cmd = self.plugIn.QadCommands.getCommandObj(QadMsg.translate("Command_list", "OPTIONS"))
icon = cmd.getIcon()
if icon is None:
optionsCmdAction = QAction(cmd.getName(), popupMenu)
else:
optionsCmdAction = QAction(icon, cmd.getName(), popupMenu)
cmd.connectQAction(optionsCmdAction)
popupMenu.addAction(optionsCmdAction)
popupMenu.popup(self.canvas.mapToGlobal(pos))
#============================================================================
# runCmdFromPopupMenuOnGrip
#============================================================================
def runCmdFromPopupMenuOnGrip(self, virtualGripCommand, gripPoint):
# seleziona il grip
gripPoint.select()
# lancio il comando
self.plugIn.runCommand("QadVirtualGripCommandsClass", [virtualGripCommand, self.entitySetGripPoints, gripPoint.getPoint()])
#============================================================================
# displayPopupMenuOnGrip
#============================================================================
def displayPopupMenuOnGrip(self, pos, entity, gripPoint):
if self.gripPopupMenu is not None:
self.gripPopupMenu.hide()
del self.gripPopupMenu
self.gripPopupMenu = None
popupMenu = QadGripPopupMenu(self.canvas)
found = False
# verifico se l'entità appartiene ad uno stile di quotatura
if QadDimStyles.isDimEntity(entity):
pass
else:
qadGeom = entity.getQadGeom(gripPoint.atGeom, gripPoint.atSubGeom)
qadGeomType = qadGeom.whatIs()
if qadGeomType == "ARC":
qadGeom = entity.getQadGeom(gripPoint.atGeom, gripPoint.atSubGeom)
# se punti finali
if gripPoint.isIntersecting(qadGeom.getStartPt()) or gripPoint.isIntersecting(qadGeom.getEndPt()):
found = True
msg = QadMsg.translate("Popup_menu_grip_window", "Stretch")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.STRECTH, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Lengthen")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.LENGTHEN, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
# se punto medio
elif gripPoint.isIntersecting(qadGeom.getMiddlePt()):
found = True
msg = QadMsg.translate("Popup_menu_grip_window", "Stretch")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.STRECTH, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Radius")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.CHANGE_RADIUS, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Convert to line")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.ARC_TO_LINE, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
if qadGeomType == "LINE":
qadGeom = entity.getQadGeom(gripPoint.atGeom, gripPoint.atSubGeom)
# se punti finali
if gripPoint.isIntersecting(qadGeom.getStartPt()) or gripPoint.isIntersecting(qadGeom.getEndPt()):
found = True
msg = QadMsg.translate("Popup_menu_grip_window", "Stretch")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.STRECTH, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Lengthen")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.LENGTHEN, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
elif qadGeomType == "POLYLINE":
isClosed = qadGeom.isClosed()
nVertex = 0
found = False
while nVertex < qadGeom.qty():
linearObject = qadGeom.getLinearObjectAt(nVertex)
if gripPoint.isIntersecting(linearObject.getStartPt()):
found = True
msg = QadMsg.translate("Popup_menu_grip_window", "Stretch vertex")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.STRECTH, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
# punto iniziale
if isClosed == False and nVertex == 0:
msg = QadMsg.translate("Popup_menu_grip_window", "Lengthen")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.LENGTHEN, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Add vertex")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.ADD_VERTEX, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Add vertex before")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.ADD_VERTEX_BEFORE, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
break
# punto medio
if gripPoint.isIntersecting(linearObject.getMiddlePt()):
found = True
msg = QadMsg.translate("Popup_menu_grip_window", "Stretch")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.STRECTH, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Add vertex")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.ADD_VERTEX, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Add vertex before")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.ADD_VERTEX_BEFORE, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
gType = linearObject.whatIs()
if gType == "LINE":
msg = QadMsg.translate("Popup_menu_grip_window", "Convert to arc")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.LINE_TO_ARC, gripPoint)
elif gType == "ARC":
msg = QadMsg.translate("Popup_menu_grip_window", "Convert to line")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.ARC_TO_LINE, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
break
nVertex = nVertex + 1
linearObject = qadGeom.getLinearObjectAt(-1) # ultima parte
if not found and isClosed == False:
# punto finale
if gripPoint.isIntersecting(linearObject.getEndPt()):
found = True
msg = QadMsg.translate("Popup_menu_grip_window", "Stretch vertex")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.STRECTH, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Lengthen")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.LENGTHEN, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Add vertex")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.ADD_VERTEX, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
msg = QadMsg.translate("Popup_menu_grip_window", "Add vertex before")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.ADD_VERTEX_BEFORE, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
if isClosed == False: # polyline
# ci devono essere almeno 2 parti
if qadGeom.qty() >= 2:
msg = QadMsg.translate("Popup_menu_grip_window", "Remove vertex")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.REMOVE_VERTEX, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
else: # polygon
# ci devono essere almeno 4 parti
if qadGeom.qty() >= 4:
msg = QadMsg.translate("Popup_menu_grip_window", "Remove vertex")
action = QAction(msg, popupMenu)
f = lambda : self.runCmdFromPopupMenuOnGrip(QadVirtualGripCommandsEnum.REMOVE_VERTEX, gripPoint)
action.triggered.connect(f)
popupMenu.addAction(action)
if found: # menu non vuoto
popupMenu.popup(self.canvas.mapToGlobal(pos))
self.gripPopupMenu = popupMenu
return None
#============================================================================
# QadGripPopupMenu
#============================================================================
class QadGripPopupMenu(QMenu):
def __init__(self, parent):
QMenu.__init__(self, parent)
self.offset = 0
#============================================================================
# popup
#============================================================================
def popup(self, pos, action = None):
newPos = QPoint(pos.x() + self.offset, pos.y() + self.offset)
QMenu.popup(self, newPos, action)
# def leaveEvent(self, event):
# if event.pos().x() < -1 * self.offset or event.pos().y() < -1 * self.offset:
# self.hide()
#self.hide()
#============================================================================
# mouseMoveEvent
#============================================================================
def mouseMoveEvent(self, event):
x = event.pos().x()
y = event.pos().y()
if x < -1 * self.offset or y < -1 * self.offset or \
x > self.width() or y > self.height():
self.hide()
else:
QMenu.mouseMoveEvent(self, event)
#============================================================================
# QadVirtualSelCommandClass
# Classe che gestisce il comando di selezione quando QAD è in stato di quiete
#============================================================================
class QadVirtualSelCommandClass(QadCommandClass):
#============================================================================
# instantiateNewCmd
#============================================================================
def instantiateNewCmd(self):
""" istanzia un nuovo comando dello stesso tipo """
return QadVirtualSelCommandClass(self.plugIn)
#============================================================================
# getName
#============================================================================
def getName(self):
return "QadVirtualSelCommandClass"
#============================================================================
# __init__
#============================================================================
def __init__(self, plugIn):
QadCommandClass.__init__(self, plugIn)
self.SSGetClass = QadSSGetClass(plugIn)
self.SSGetClass.entitySet.set(plugIn.tool.entitySet) # da usare solo con QadMapTool
self.SSGetClass.exitAfterSelection = True
self.SSGetClass.step = 1
#============================================================================
# __del__
#============================================================================
def __del__(self):
QadCommandClass.__del__(self)
del self.SSGetClass
#============================================================================
# getPointMapTool
#============================================================================
def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE):
return self.SSGetClass.getPointMapTool(drawMode)
#============================================================================
# run
#============================================================================
def run(self, msgMapTool = False, msg = None):
res = self.SSGetClass.run(msgMapTool, msg)
if res == True:
self.plugIn.tool.entitySet.set(self.SSGetClass.entitySet) # da usare solo con QadMapTool
self.plugIn.tool.entitySet.selectOnLayer()
return res
#===============================================================================
# QadVirtualGripCommandsEnum class.
#===============================================================================
class QadVirtualGripCommandsEnum():
NONE = 0
STRECTH = 1
MOVE = 2
ROTATE = 3
SCALE = 4
MIRROR = 5
LENGTHEN = 6
ADD_VERTEX = 7
REMOVE_VERTEX = 8
LINE_TO_ARC = 9
ARC_TO_LINE = 10
CHANGE_RADIUS = 11
ADD_VERTEX_BEFORE = 12
#============================================================================
# QadVirtualGripCommandsClass
#============================================================================
# Classe che gestisce i comando disponibili sui grip quando QAD è in stato di quiete
class QadVirtualGripCommandsClass(QadCommandClass):
#============================================================================
# instantiateNewCmd
#============================================================================
def instantiateNewCmd(self):
""" istanzia un nuovo comando dello stesso tipo """
return QadVirtualGripCommandsClass(self.plugIn)
#============================================================================
# getName
#============================================================================
def getName(self):
return "QadVirtualGripCommandsClass"
#============================================================================
# __init__
#============================================================================
def __init__(self, plugIn):
QadCommandClass.__init__(self, plugIn)
self.commandNum = QadVirtualGripCommandsEnum.NONE
self.currentCommand = None
self.entitySetGripPoints = None
self.basePt = QgsPointXY()
#============================================================================
# __del__
#============================================================================
def __del__(self):
QadCommandClass.__del__(self)
del self.currentCommand
#============================================================================
# getPointMapTool
#============================================================================
def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE):
if self.currentCommand is not None:
return self.currentCommand.getPointMapTool(drawMode)
else:
return None
#============================================================================
# getCurrentContextualMenu
#============================================================================
def getCurrentContextualMenu(self):
if self.currentCommand is not None:
return self.currentCommand.getCurrentContextualMenu()
else:
return None
#============================================================================
# getCommand
#============================================================================
def getCommand(self):
if self.commandNum == QadVirtualGripCommandsEnum.STRECTH:
return QadGRIPSTRETCHCommandClass(self.plugIn)
elif self.commandNum == QadVirtualGripCommandsEnum.MOVE:
return QadGRIPMOVECommandClass(self.plugIn)
elif self.commandNum == QadVirtualGripCommandsEnum.ROTATE:
return QadGRIPROTATECommandClass(self.plugIn)
elif self.commandNum == QadVirtualGripCommandsEnum.SCALE:
return QadGRIPSCALECommandClass(self.plugIn)
elif self.commandNum == QadVirtualGripCommandsEnum.MIRROR:
return QadGRIPMIRRORCommandClass(self.plugIn)
elif self.commandNum == QadVirtualGripCommandsEnum.CHANGE_RADIUS:
return QadGRIPCHANGEARCRADIUSCommandClass(self.plugIn)
elif self.commandNum == QadVirtualGripCommandsEnum.LENGTHEN:
return QadGRIPLENGTHENCommandClass(self.plugIn)
elif self.commandNum == QadVirtualGripCommandsEnum.ADD_VERTEX:
cmd = QadGRIPINSERTREMOVEVERTEXCommandClass(self.plugIn)
cmd.setInsertVertexAfter_Mode()
return cmd
elif self.commandNum == QadVirtualGripCommandsEnum.ADD_VERTEX_BEFORE:
cmd = QadGRIPINSERTREMOVEVERTEXCommandClass(self.plugIn)
cmd.setInsertVertexBefore_Mode()
return cmd
elif self.commandNum == QadVirtualGripCommandsEnum.REMOVE_VERTEX:
cmd = QadGRIPINSERTREMOVEVERTEXCommandClass(self.plugIn)
cmd.setRemoveVertex_mode()
return cmd
elif self.commandNum == QadVirtualGripCommandsEnum.LINE_TO_ARC:
cmd = QadGRIPARCLINECONVERTCommandClass(self.plugIn)
cmd.setLineToArcConvert_Mode()
return cmd
elif self.commandNum == QadVirtualGripCommandsEnum.ARC_TO_LINE:
cmd = QadGRIPARCLINECONVERTCommandClass(self.plugIn)
cmd.setArcToLineConvert_Mode()
return cmd
return None
#============================================================================
# initStartCommand
#============================================================================
def initStartCommand(self, commandNum):
if self.currentCommand is not None:
del self.currentCommand
self.currentCommand = None
self.commandNum = commandNum
self.currentCommand = self.getCommand()
if self.currentCommand is not None:
self.currentCommand.basePt.set(self.basePt.x(), self.basePt.y())
self.currentCommand.setSelectedEntityGripPoints(self.entitySetGripPoints)
return True
else:
return False
#============================================================================
# initNextCommand
#============================================================================
def initNextCommand(self):
if self.currentCommand is not None:
del self.currentCommand
self.currentCommand = None
if self.commandNum == QadVirtualGripCommandsEnum.STRECTH or \
self.commandNum == QadVirtualGripCommandsEnum.LENGTHEN or \
self.commandNum == QadVirtualGripCommandsEnum.ADD_VERTEX or \
self.commandNum == QadVirtualGripCommandsEnum.ADD_VERTEX_BEFORE or \
self.commandNum == QadVirtualGripCommandsEnum.REMOVE_VERTEX or \
self.commandNum == QadVirtualGripCommandsEnum.LINE_TO_ARC or \
self.commandNum == QadVirtualGripCommandsEnum.ARC_TO_LINE or \
self.commandNum == QadVirtualGripCommandsEnum.CHANGE_RADIUS:
self.commandNum = QadVirtualGripCommandsEnum.MOVE
elif self.commandNum == QadVirtualGripCommandsEnum.MOVE:
self.commandNum = QadVirtualGripCommandsEnum.ROTATE
elif self.commandNum == QadVirtualGripCommandsEnum.ROTATE:
self.commandNum = QadVirtualGripCommandsEnum.SCALE
elif self.commandNum == QadVirtualGripCommandsEnum.SCALE:
self.commandNum = QadVirtualGripCommandsEnum.MIRROR
elif self.commandNum == QadVirtualGripCommandsEnum.MIRROR:
self.commandNum = QadVirtualGripCommandsEnum.MOVE
self.currentCommand = self.getCommand()
if self.currentCommand is not None:
self.currentCommand.basePt.set(self.basePt.x(), self.basePt.y())
self.currentCommand.setSelectedEntityGripPoints(self.entitySetGripPoints)
return True
else:
return False
#============================================================================
# run
#============================================================================
def run(self, msgMapTool = False, msg = None):
if self.currentCommand is None:
return True
res = self.currentCommand.run(msgMapTool, msg)
if res == True:
if self.currentCommand.skipToNextGripCommand == True:
if self.initNextCommand(): # attivo comando successivo
return self.currentCommand.run(msgMapTool, msg)
else:
# ridisegno i grip point nelle nuove posizioni resettando quelli selezionati
self.plugIn.tool.clearEntityGripPoints()
self.plugIn.tool.refreshEntityGripPoints()
return res