-
Notifications
You must be signed in to change notification settings - Fork 21
/
qad_getangle_cmd.py
154 lines (129 loc) · 7 KB
/
qad_getangle_cmd.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
comando da inserire in altri comandi per la richiesta di un angolo
-------------------
begin : 2013-12-04
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. *
* *
***************************************************************************/
"""
# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qad_generic_cmd import QadCommandClass
from qad_msg import QadMsg
from qad_textwindow import *
from qad_entity import *
from qad_getpoint import *
import qad_utils
#===============================================================================
# QadGetAngleClass
#===============================================================================
class QadGetAngleClass(QadCommandClass):
def instantiateNewCmd(self):
""" istanzia un nuovo comando dello stesso tipo """
return QadGetAngleClass(self.plugIn)
def __init__(self, plugIn):
QadCommandClass.__init__(self, plugIn)
self.entity = QadEntity()
self.startPt = None
self.msg = QadMsg.translate("QAD", "Specify angle: ")
self.angle = None # in radianti
# memorizzo last point perchè il/i punto/i indicato/i da questa questa funzione non devono
# alterare lastpoint
self.__prevLastPoint = self.plugIn.lastPoint
def run(self, msgMapTool = False, msg = None):
if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag():
self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n"))
return True # fine comando
#=========================================================================
# RICHIESTA PUNTO o ENTITA'
if self.step == 0: # inizio del comando
# si appresta ad attendere un punto o un numero reale
# msg, inputType, default, keyWords, valori non nulli
self.waitFor(self.msg, \
QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \
self.angle, "", \
QadInputModeEnum.NOT_NULL)
if self.startPt is not None:
# imposto il map tool
self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
self.getPointMapTool().setStartPoint(self.startPt)
self.step = 1
return False
#=========================================================================
# RISPOSTA ALLA RICHIESTA PUNTO O NUMERO REALE
elif self.step == 1: # dopo aver atteso un punto si riavvia il comando
if msgMapTool == True: # il punto arriva da una selezione grafica
# la condizione seguente si verifica se durante la selezione di un punto
# é stato attivato un altro plugin che ha disattivato Qad
# quindi stato riattivato il comando che torna qui senza che il maptool
# abbia selezionato un punto
if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
return True # fine comando
else:
self.setMapTool(self.getPointMapTool()) # riattivo il maptool
return False
value = self.getPointMapTool().point
else: # il punto o il numero reale arriva come parametro della funzione
value = msg
if value is None:
return True # fine comando
if type(value) == float:
self.angle = qad_utils.toRadians(value)
return True # fine comando
elif type(value) == QgsPoint:
# il/i punto/i indicato/i da questa questa funzione non devono alterare lastpoint
self.plugIn.setLastPoint(self.__prevLastPoint)
if self.startPt is not None:
self.angle = qad_utils.getAngleBy2Pts(self.startPt, value)
return True # fine comando
else:
self.startPt = value
# imposto il map tool
self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
self.getPointMapTool().setStartPoint(self.startPt)
# si appresta ad attendere un punto
self.waitForPoint(QadMsg.translate("QAD", "Specify second point: "))
self.step = 2
return False
#=========================================================================
# RISPOSTA ALLA RICHIESTA SECONDO PUNTO DELLA ANGOLO (da step = 1)
elif self.step == 2: # dopo aver atteso un punto si riavvia il comando
if msgMapTool == True: # il punto arriva da una selezione grafica
# la condizione seguente si verifica se durante la selezione di un punto
# é stato attivato un altro plugin che ha disattivato Qad
# quindi stato riattivato il comando che torna qui senza che il maptool
# abbia selezionato un punto
if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
return True # fine comando
else:
self.setMapTool(self.getPointMapTool()) # riattivo il maptool
return False
value = self.getPointMapTool().point
else: # il punto arriva come parametro della funzione
value = msg
# il/i punto/i indicato/i da questa questa funzione non devono alterare lastpoint
self.plugIn.setLastPoint(self.__prevLastPoint)
if qad_utils.ptNear(self.startPt, value):
self.showMsg(QadMsg.translate("QAD", "\nThe points must be different."))
# si appresta ad attendere un punto
self.waitForPoint(QadMsg.translate("QAD", "Specify second point: "))
return False
else:
self.angle = qad_utils.getAngleBy2Pts(self.startPt, value)
return True # fine comando