forked from geosim/QAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qad_mpolygon_cmd.py
129 lines (104 loc) · 5.43 KB
/
qad_mpolygon_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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
comando MPOLYGON per disegnare un poligono
-------------------
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_pline_cmd import QadPLINECommandClass
from qad_msg import QadMsg
from qad_textwindow import *
from qad_getpoint import *
import qad_utils
import qad_layer
# Classe che gestisce il comando MPOLYGON
class QadMPOLYGONCommandClass(QadCommandClass):
def instantiateNewCmd(self):
""" istanzia un nuovo comando dello stesso tipo """
return QadMPOLYGONCommandClass(self.plugIn)
def getName(self):
return QadMsg.translate("Command_list", "MPOLIGONO")
def getEnglishName(self):
return "MPOLYGON"
def connectQAction(self, action):
QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runMPOLYGONCommand)
def getIcon(self):
return QIcon(":/plugins/qad/icons/mpolygon.png")
def getNote(self):
# impostare le note esplicative del comando
return QadMsg.translate("Command_MPOLYGON", "Disegna un poligono mediante diversi metodi.\n\nUn poligono é una sequenza chiusa di segmenti retti,\narchi o una combinazione dei due.")
def __init__(self, plugIn):
QadCommandClass.__init__(self, plugIn)
self.vertices = []
# se questo flag = True il comando serve all'interno di un altro comando per disegnare un poligono
# che non verrà salvato su un layer
self.virtualCmd = False
self.PLINECommand = None
def __del__(self):
QadCommandClass.__del__(self)
del self.SSGetClass
def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE):
if self.PLINECommand is not None:
return self.PLINECommand.getPointMapTool(drawMode)
else:
return QadCommandClass.getPointMapTool(self, drawMode)
def run(self, msgMapTool = False, msg = None):
if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag():
self.showMsg(QadMsg.translate("QAD", "\nIl sistema di riferimento del progetto deve essere un sistema di coordinate proiettate.\n"))
return True # fine comando
if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer
currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, QGis.Polygon)
if currLayer is None:
self.showErr(errMsg)
return True # fine comando
#=========================================================================
# RICHIESTA PRIMO PUNTO PER SELEZIONE OGGETTI
if self.step == 0:
self.PLINECommand = QadPLINECommandClass(self.plugIn, True)
# se questo flag = True il comando serve all'interno di un altro comando per disegnare una linea
# che non verrà salvata su un layer
self.PLINECommand.virtualCmd = True
self.PLINECommand.asToolForMPolygon = True # per rubberband tipo poligono
self.PLINECommand.run(msgMapTool, msg)
self.step = 1
return False # continua
#=========================================================================
# RISPOSTA ALLA RICHIESTA PUNTO (da step = 0 o 1)
elif self.step == 1: # dopo aver atteso un punto si riavvia il comando
if self.PLINECommand.run(msgMapTool, msg) == True:
verticesLen = len(self.PLINECommand.vertices)
if verticesLen > 3:
self.vertices = self.PLINECommand.vertices[:] # copio la lista
firstVertex = self.vertices[0]
# se l'ultimo vertice non é uguale al primo
if self.vertices[verticesLen - 1] != firstVertex:
# aggiungo un vertice con le stesse coordinate del primo
self.vertices.append(firstVertex)
if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer
if qad_layer.addPolygonToLayer(self.plugIn, currLayer, self.vertices) == False:
self.showMsg(QadMsg.translate("Command_MPOLYGON", "\nPoligono non valido.\n"))
del self.vertices[:] # svuoto la lista
else:
self.showMsg(QadMsg.translate("Command_MPOLYGON", "\nPoligono non valido.\n"))
del self.PLINECommand
self.PLINECommand = None
return True # fine
return False