forked from geosim/QAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qad_setcurrlayerbygraph_cmd.py
184 lines (146 loc) · 7.9 KB
/
qad_setcurrlayerbygraph_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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
comando SETCURRLAYERBYGRAPH per settare il layer corrente tramite selezione grafica
comando SETCURRUPDATEABLELAYERBYGRAPH per settare il layer corrente e porlo in modifica
tramite selezione grafica
------------------
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 PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qad_generic_cmd import QadCommandClass
from qad_snapper import *
from qad_getpoint import *
from qad_entsel_cmd import QadEntSelClass
from qad_ssget_cmd import QadSSGetClass
from qad_msg import QadMsg
# Classe che gestisce il comando SETCURRLAYERBYGRAPH
class QadSETCURRLAYERBYGRAPHCommandClass(QadCommandClass):
def instantiateNewCmd(self):
""" istanzia un nuovo comando dello stesso tipo """
return QadSETCURRLAYERBYGRAPHCommandClass(self.plugIn)
def getName(self):
return QadMsg.translate("Command_list", "SETCURRLAYERBYGRAPH")
def getEnglishName(self):
return "SETCURRLAYERBYGRAPH"
def connectQAction(self, action):
QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runSETCURRLAYERBYGRAPHCommand)
def getIcon(self):
return QIcon(":/plugins/qad/icons/setcurrlayerbygraph.png")
def getNote(self):
# impostare le note esplicative del comando
return QadMsg.translate("Command_SETCURRLAYERBYGRAPH", "Sets a layer of a graphical object as current.")
def __init__(self, plugIn):
QadCommandClass.__init__(self, plugIn)
self.EntSelClass = None
def __del__(self):
QadCommandClass.__del__(self)
def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE):
if self.step == 0 or self.step == 1: # quando si é in fase di selezione entità
return self.EntSelClass.getPointMapTool(drawMode)
else:
return QadCommandClass.getPointMapTool(self, drawMode)
def waitForEntsel(self, msgMapTool, msg):
if self.EntSelClass is not None:
del self.EntSelClass
self.EntSelClass = QadEntSelClass(self.plugIn)
self.EntSelClass.msg = QadMsg.translate("Command_SETCURRLAYERBYGRAPH", "Select object whose layer will be the current layer: ")
self.getPointMapTool().setSnapType(QadSnapTypeEnum.DISABLE)
self.EntSelClass.run(msgMapTool, msg)
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
if self.step == 0:
self.waitForEntsel(msgMapTool, msg)
self.step = 1
return False # continua
elif self.step == 1:
if self.EntSelClass.run(msgMapTool, msg) == True:
if self.EntSelClass.entity.isInitialized():
layer = self.EntSelClass.entity.layer
if self.plugIn.canvas.currentLayer() is None or \
self.plugIn.canvas.currentLayer() != layer:
self.plugIn.canvas.setCurrentLayer(layer)
self.plugIn.iface.setActiveLayer(layer) # lancia evento di deactivate e activate dei plugin
self.plugIn.iface.legendInterface().refreshLayerSymbology(layer)
msg = QadMsg.translate("Command_SETCURRLAYERBYGRAPH", "\nThe current layer is {0}.")
self.showMsg(msg.format(layer.name()))
del self.EntSelClass
return True
else:
self.showMsg(QadMsg.translate("Command_SETCURRLAYERBYGRAPH", "No geometries in this position."))
self.waitForEntsel(msgMapTool, msg)
return False # continua
# Classe che gestisce il comando SETCURRUPDATEABLELAYERBYGRAPH
class QadSETCURRUPDATEABLELAYERBYGRAPHCommandClass(QadCommandClass):
def instantiateNewCmd(self):
""" istanzia un nuovo comando dello stesso tipo """
return QadSETCURRUPDATEABLELAYERBYGRAPHCommandClass(self.plugIn)
def getName(self):
return QadMsg.translate("Command_list", "SETCURRUPDATEABLELAYERBYGRAPH")
def getEnglishName(self):
return "SETCURRUPDATEABLELAYERBYGRAPH"
def connectQAction(self, action):
QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runSETCURRUPDATEABLELAYERBYGRAPHCommand)
def getIcon(self):
return QIcon(":/plugins/qad/icons/setcurrupdateablelayerbygraph.png")
def getNote(self):
# impostare le note esplicative del comando
return QadMsg.translate("Command_SETCURRUPDATEABLELAYERBYGRAPH", "Sets the layers of a graphical objects as editable.")
def __init__(self, plugIn):
QadCommandClass.__init__(self, plugIn)
self.SSGetClass = QadSSGetClass(plugIn)
self.firstTime = True
def __del__(self):
QadCommandClass.__del__(self)
del self.SSGetClass
def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE):
if self.step == 0: # quando si é in fase di selezione entità
return self.SSGetClass.getPointMapTool(drawMode)
else:
return QadCommandClass.getPointMapTool(self, drawMode)
def run(self, msgMapTool = False, msg = None):
if self.step == 0: # inizio del comando
if self.firstTime == True:
self.showMsg(QadMsg.translate("Command_SETCURRUPDATEABLELAYERBYGRAPH", "\nSelect objects whose layers will be the editable: "))
self.firstTime = False
if self.SSGetClass.run(msgMapTool, msg) == True:
# selezione terminata
self.step = 1
return self.run(msgMapTool, msg)
else:
return False # continua
elif self.step == 1: # dopo aver atteso la selezione di oggetti
message = ""
for layerEntitySet in self.SSGetClass.entitySet.layerEntitySetList:
layer = layerEntitySet.layer
if layer.isEditable() == False:
if layer.startEditing() == True:
self.plugIn.iface.legendInterface().refreshLayerSymbology(layer)
self.showMsg(QadMsg.translate("Command_SETCURRUPDATEABLELAYERBYGRAPH", "\nThe layer {0} is editable.").format(layer.name()))
if len(self.SSGetClass.entitySet.layerEntitySetList) == 1:
layer = self.SSGetClass.entitySet.layerEntitySetList[0].layer
if self.plugIn.canvas.currentLayer() is None or \
self.plugIn.canvas.currentLayer() != layer:
self.plugIn.canvas.setCurrentLayer(layer)
self.plugIn.iface.setActiveLayer(layer) # lancia evento di deactivate e activate dei plugin
self.plugIn.iface.legendInterface().refreshLayerSymbology(layer)
self.showMsg(QadMsg.translate("Command_SETCURRUPDATEABLELAYERBYGRAPH", "\nThe current layer is {0}.").format(layer.name()))
return True