forked from geosim/QAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qad_entsel_cmd.py
192 lines (161 loc) · 8.52 KB
/
qad_entsel_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
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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
comando da inserire in altri comandi per la selezione di una feature
-------------------
begin : 2013-09-18
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
from qad_dim import QadDimStyles
#===============================================================================
# QadEntSelClass
#===============================================================================
class QadEntSelClass(QadCommandClass):
"""
Questa classe seleziona un'entità. Non è in grado di selezionare una quotatura ma solo un componente di una quotatura.
"""
def instantiateNewCmd(self):
""" istanzia un nuovo comando dello stesso tipo """
return QadEntSelClass(self.plugIn)
def __init__(self, plugIn):
QadCommandClass.__init__(self, plugIn)
self.entity = QadEntity()
self.point = None
# opzioni per limitare gli oggetti da selezionare
self.onlyEditableLayers = False
self.checkPointLayer = True
self.checkLineLayer = True
self.checkPolygonLayer = True
self.checkDimLayers = True
self.selDimEntity = False # per restituire o meno un oggetto QadDimEntity
self.msg = QadMsg.translate("QAD", "Select object: ")
def __del__(self):
QadCommandClass.__del__(self)
if self.entity.isInitialized():
self.entity.deselectOnLayer()
#============================================================================
# setEntity
#============================================================================
def setEntity(self, layer, fid):
del self.entity
if self.selDimEntity: # se è possibile restituire un oggetto QadDimEntity
# verifico se l'entità appartiene ad uno stile di quotatura
self.entity = QadDimStyles.getDimEntity(layer, fid)
if self.entity is None: # se non è una quota
self.entity = QadEntity()
self.entity.set(layer, fid)
else:
self.entity = QadEntity()
self.entity.set(layer, fid)
self.entity.selectOnLayer()
#============================================================================
# getLayersToCheck
#============================================================================
def getLayersToCheck(self):
layerList = []
for layer in self.plugIn.canvas.layers(): # Tutti i layer visibili visibili
# considero solo i layer vettoriali che sono filtrati per tipo
if (layer.type() == QgsMapLayer.VectorLayer) and \
((layer.geometryType() == QGis.Point and self.checkPointLayer == True) or \
(layer.geometryType() == QGis.Line and self.checkLineLayer == True) or \
(layer.geometryType() == QGis.Polygon and self.checkPolygonLayer == True)) and \
(self.onlyEditableLayers == False or layer.isEditable()):
# se devo includere i layers delle quotature
if self.checkDimLayers == True or \
len(QadDimStyles.getDimListByLayer(layer)) == 0:
layerList.append(layer)
return layerList
def run(self, msgMapTool = False, msg = None):
if self.plugIn.canvas.mapRenderer().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
# imposto il map tool
self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.ENTITY_SELECTION)
# imposto i layer da controllare sul maptool
self.getPointMapTool().layersToCheck = self.getLayersToCheck()
keyWords = QadMsg.translate("Command_ENTSEL", "Last")
englishKeyWords = "Last"
keyWords += "_" + englishKeyWords
# si appresta ad attendere un punto o enter o una parola chiave
# msg, inputType, default, keyWords, nessun controllo
self.waitFor(self.msg, \
QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \
None, \
keyWords, QadInputModeEnum.NONE)
self.step = 1
return False
#=========================================================================
# RISPOSTA ALLA RICHIESTA PUNTO o ENTITA'
elif self.step == 1: # dopo aver atteso un punto si riavvia il comando
entity = None
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
if self.getPointMapTool().entity.isInitialized():
entity = self.getPointMapTool().entity
else: # il punto arriva come parametro della funzione
value = msg
if value is None:
return True # fine comando
if type(value) == unicode:
if value == QadMsg.translate("Command_ENTSEL", "Last") or value == "Last":
# Seleziona l'ultima entità inserita
lastEnt = self.plugIn.getLastEntity()
if lastEnt is not None:
# controllo sul layer
if self.onlyEditableLayers == False or lastEnt.layer.isEditable() == True:
# controllo sul tipo
if (self.checkPointLayer == True and lastEnt.layer.geometryType() == QGis.Point) or \
(self.checkLineLayer == True and lastEnt.layer.geometryType() == QGis.Line) or \
(self.checkPolygonLayer == True and lastEnt.layer.geometryType() == QGis.Polygon):
# controllo su layer delle quotature
if self.checkDimLayers == True or lastEnt.isDimensionComponent() == False:
self.setEntity(lastEnt.layer, lastEnt.featureId)
elif type(value) == QgsPoint:
if entity is None:
# cerco se ci sono entità nel punto indicato
result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value),
self.getPointMapTool(), \
self.getLayersToCheck())
if result is not None:
feature = result[0]
layer = result[1]
self.setEntity(layer, feature.id())
else:
self.setEntity(entity.layer, entity.featureId)
self.point = value
return True # fine comando