-
Notifications
You must be signed in to change notification settings - Fork 21
/
qad_rectangle_maptool.py
122 lines (98 loc) · 4.63 KB
/
qad_rectangle_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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
classe per gestire il map tool in ambito del comando rectangle
-------------------
begin : 2013-12-3
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 PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
import math
import qad_utils
from qad_snapper import *
from qad_snappointsdisplaymanager import *
from qad_variables import *
from qad_getpoint import *
from qad_rubberband import QadRubberBand
#===============================================================================
# Qad_rectangle_maptool_ModeEnum class.
#===============================================================================
class Qad_rectangle_maptool_ModeEnum():
# noto niente si richiede il primo angolo
NONE_KNOWN_ASK_FOR_FIRST_CORNER = 1
# noto il primo angolo si richiede l'angolo opposto
FIRST_CORNER_KNOWN_ASK_FOR_SECOND_CORNER = 2
#===============================================================================
# Qad_rotate_maptool class
#===============================================================================
class Qad_rectangle_maptool(QadGetPoint):
def __init__(self, plugIn):
QadGetPoint.__init__(self, plugIn)
self.firstCorner = None
self.secondCorner = None
self.basePt = None
self.gapType = 0 # 0 = Angoli retti; 1 = Raccorda i segmenti; 2 = Cima i segmenti
self.gapValue1 = 0 # se gapType = 1 -> raggio di curvatura; se gapType = 2 -> prima distanza di cimatura
self.gapValue2 = 0 # se gapType = 2 -> seconda distanza di cimatura
self.rot = 0
self.vertices = []
self.__rubberBand = QadRubberBand(self.canvas, True)
self.geomType = QGis.Polygon
def hidePointMapToolMarkers(self):
QadGetPoint.hidePointMapToolMarkers(self)
self.__rubberBand.hide()
def showPointMapToolMarkers(self):
QadGetPoint.showPointMapToolMarkers(self)
self.__rubberBand.show()
def clear(self):
QadGetPoint.clear(self)
self.__rubberBand.reset()
self.mode = None
def canvasMoveEvent(self, event):
QadGetPoint.canvasMoveEvent(self, event)
self.__rubberBand.reset()
result = False
del self.vertices[:] # svuoto la lista
# noto il primo angolo si richiede l'angolo opposto
if self.mode == Qad_rectangle_maptool_ModeEnum.FIRST_CORNER_KNOWN_ASK_FOR_SECOND_CORNER:
self.vertices.extend(qad_utils.getRectByCorners(self.firstCorner, self.tmpPoint, self.rot, \
self.gapType, self.gapValue1, self.gapValue2))
result = True
if result == True:
if self.vertices is not None:
if self.geomType == QGis.Polygon:
self.__rubberBand.setPolygon(self.vertices)
else:
self.__rubberBand.setLine(self.vertices)
def activate(self):
QadGetPoint.activate(self)
self.__rubberBand.show()
def deactivate(self):
try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
QadGetPoint.deactivate(self)
self.__rubberBand.hide()
except:
pass
def setMode(self, mode):
self.mode = mode
# noto niente si richiede il primo angolo
if self.mode == Qad_rectangle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_CORNER:
self.setDrawMode(QadGetPointDrawModeEnum.NONE)
# noto il primo angolo si richiede l'angolo opposto
elif self.mode == Qad_rectangle_maptool_ModeEnum.FIRST_CORNER_KNOWN_ASK_FOR_SECOND_CORNER:
self.setDrawMode(QadGetPointDrawModeEnum.NONE)