개정판 ed948580
fixed some bugs
DTI_PID/DTI_PID/Commands/DefaultCommand.py | ||
---|---|---|
117 | 117 |
scenePos = QPointF(item.center()[0], item.center()[1]) |
118 | 118 |
|
119 | 119 |
transform = QTransform() |
120 |
transform.translate(scenePos.x(), scenePos.y()) |
|
120 |
currentPt = self.symbol.getCurrentPoint() |
|
121 |
transform.translate(scenePos.x() - currentPt[0], scenePos.y() - currentPt[1]) |
|
121 | 122 |
self.symbol.setTransform(transform) |
122 | 123 |
|
123 | 124 |
self.imageViewer.scene.removeItem(self.symbol) |
... | ... | |
134 | 135 |
scenePos = QPointF(item.center()[0], item.center()[1]) |
135 | 136 |
|
136 | 137 |
transform = QTransform() |
137 |
transform.translate(scenePos.x() - self.symbol.symbolOrigin[0], scenePos.y() - self.symbol.symbolOrigin[1]) |
|
138 |
currentPt = self.symbol.getCurrentPoint() |
|
139 |
transform.translate(scenePos.x() - currentPt[0], scenePos.y() - currentPt[1]) |
|
138 | 140 |
self.symbol.setTransform(transform) |
139 | 141 |
elif 'keyPressEvent' == param[0] and event.key() == Qt.Key_Escape: |
140 | 142 |
self.imageViewer.scene.removeItem(self.symbol) |
... | ... | |
174 | 176 |
# uid 새로 할당 |
175 | 177 |
self.symbol.uid = uuid.uuid4() |
176 | 178 |
self.imageViewer.scene.addItem(self.symbol) |
179 |
self.imageViewer.scene.clearFocus() |
|
180 |
self.imageViewer.scene.setFocusItem(self.symbol) |
|
181 |
self.symbol.setSelected(True) |
|
177 | 182 |
self.isCopy = True |
178 | 183 |
|
179 | 184 |
QApplication.instance().setOverrideCursor(QCursor(Qt.DragCopyCursor)) |
DTI_PID/DTI_PID/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
37 | 37 |
self.connectedItem = None |
38 | 38 |
self.sceneConnectPoint = None |
39 | 39 |
self.connectPoint = None |
40 |
self._hoverItem = None |
|
40 | 41 |
|
41 | 42 |
self.setAcceptHoverEvents(True) |
42 | 43 |
|
... | ... | |
129 | 130 |
def mouseReleaseEvent(self, event): |
130 | 131 |
import shapely |
131 | 132 |
if type(self.parent) is QEngineeringLineItem and self._savedPos is not None: |
132 |
#item = self.scene().itemAt(event.scenePos(), QTransform()) |
|
133 |
item = self.getItemsAtPoint(event.scenePos()) |
|
133 |
items = [item for item in self.scene().items(event.scenePos()) if item is not self and item is not self.parent and type(item) is not QGraphicsPixmapItem] |
|
134 | 134 |
|
135 |
if item is not None and item is not self.parent and type(item) is QEngineeringLineItem: |
|
136 |
length = item.length()*0.5 |
|
137 |
dir = item.perpendicular() |
|
138 |
start = [event.scenePos().x() - dir[0]*length, event.scenePos().y() - dir[1]*length] |
|
139 |
end = [event.scenePos().x() + dir[0]*length, event.scenePos().y() + dir[1]*length] |
|
140 |
pt = item.intersection([start, end]) |
|
135 |
if items and type(items[0]) is QEngineeringLineItem: |
|
136 |
length = items[0].length()*0.5 |
|
137 |
dir = items[0].perpendicular() |
|
138 |
if self.parent.isHorizontal(): |
|
139 |
start = [event.scenePos().x() - dir[0]*length, self.parent.startPoint()[1] - dir[1]*length] |
|
140 |
end = [event.scenePos().x() + dir[0]*length, self.parent.startPoint()[1] + dir[1]*length] |
|
141 |
else: |
|
142 |
start = [self.parent.startPoint()[0] - dir[0]*length, event.scenePos().y() - dir[1]*length] |
|
143 |
end = [self.parent.startPoint()[0] + dir[0]*length, event.scenePos().y() + dir[1]*length] |
|
144 |
|
|
145 |
pt = items[0].intersection([start, end]) |
|
141 | 146 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
142 | 147 |
self.setPos((pt.x, pt.y)) |
143 |
self.connectedItem = item |
|
144 |
elif item is not None and type(item) is QEngineeringConnectorItem and item is not self:
|
|
145 |
self.setPos(item.center()) |
|
148 |
self.connectedItem = items[0]
|
|
149 |
elif items and type(items[0]) is QEngineeringConnectorItem:
|
|
150 |
self.setPos(items[0].center())
|
|
146 | 151 |
|
147 | 152 |
if self.connectedItem is not None: |
148 | 153 |
for connect in self.connectedItem.connectors: |
149 | 154 |
if connect.connectedItem == self.parent: |
150 | 155 |
connect.connectedItem = None |
151 | 156 |
|
152 |
self.connectedItem = item.parent |
|
153 |
item.connectedItem = self.parent |
|
157 |
self.connectedItem = items[0].parent
|
|
158 |
items[0].connectedItem = self.parent
|
|
154 | 159 |
else: |
155 | 160 |
other = [connector for connector in self.parent.connectors if connector is not self] |
156 | 161 |
if other: |
... | ... | |
180 | 185 |
QGraphicsEllipseItem.mouseReleaseEvent(self, event) |
181 | 186 |
|
182 | 187 |
''' |
183 |
@brief |
|
184 |
@author kyouho |
|
185 |
@date 2018.08.10 |
|
186 |
''' |
|
187 |
def getItemsAtPoint(self, scenePos): |
|
188 |
itemList = [] |
|
189 |
items = [item for item in self.scene().items() if (type(item) is QEngineeringLineItem or type(item) is QEngineeringConnectorItem)] |
|
190 |
for item in items: |
|
191 |
# Line 아이템만 (자기 자신의 부모 제외) |
|
192 |
if type(item) is QEngineeringLineItem and item is not self.parent and item.contains(scenePos): |
|
193 |
itemList.append(item) |
|
194 |
# connector의 부모가 라인이 아닌 것만 |
|
195 |
elif type(item) is QEngineeringConnectorItem and type(item.parent) is not QEngineeringLineItem: |
|
196 |
rect = item.sceneBoundingRect() |
|
197 |
if rect.contains(scenePos): |
|
198 |
itemList.append(item) |
|
199 |
if len(itemList) > 0: |
|
200 |
return itemList[0] |
|
201 |
else: |
|
202 |
return None |
|
203 |
|
|
204 |
''' |
|
205 | 188 |
@brief move connector's position while mouse drag |
206 | 189 |
@author humkyung |
207 | 190 |
@date 2018.07.27 |
... | ... | |
211 | 194 |
|
212 | 195 |
if type(self.parent) is QEngineeringLineItem and self._savedPos is not None: |
213 | 196 |
if event.buttons() == Qt.LeftButton: |
214 |
item = self.scene().itemAt(event.scenePos(), QTransform()) |
|
215 |
if item is not None and item is not self.parent and type(item) is QEngineeringLineItem: |
|
216 |
length = item.length()*0.5 |
|
217 |
dir = item.perpendicular() |
|
218 |
start = [event.scenePos().x() - dir[0]*length, event.scenePos().y() - dir[1]*length] |
|
219 |
end = [event.scenePos().x() + dir[0]*length, event.scenePos().y() + dir[1]*length] |
|
220 |
pt = item.intersection([start, end]) |
|
197 |
items = [item for item in self.scene().items(event.scenePos()) if item is not self and item is not self.parent and type(item) is not QGraphicsPixmapItem] |
|
198 |
if items and self.parent not in items and type(items[0]) is QEngineeringLineItem: |
|
199 |
length = items[0].length()*0.5 |
|
200 |
dir = items[0].perpendicular() |
|
201 |
if self.parent.isHorizontal(): |
|
202 |
start = [event.scenePos().x() - dir[0]*length, self.parent.startPoint()[1] - dir[1]*length] |
|
203 |
end = [event.scenePos().x() + dir[0]*length, self.parent.startPoint()[1] + dir[1]*length] |
|
204 |
else: |
|
205 |
start = [self.parent.startPoint()[0] - dir[0]*length, event.scenePos().y() - dir[1]*length] |
|
206 |
end = [self.parent.startPoint()[0] + dir[0]*length, event.scenePos().y() + dir[1]*length] |
|
207 |
|
|
208 |
pt = items[0].intersection([start, end]) |
|
221 | 209 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
222 | 210 |
self.setPos((pt.x, pt.y)) |
223 |
elif item is not None and type(item) is QEngineeringConnectorItem:
|
|
224 |
self.setPos(item.center()) |
|
211 |
elif items and type(items[0]) is QEngineeringConnectorItem:
|
|
212 |
self.setPos(items[0].center())
|
|
225 | 213 |
else: |
226 | 214 |
other = [connector for connector in self.parent.connectors if connector is not self] |
227 | 215 |
if other: |
... | ... | |
235 | 223 |
|
236 | 224 |
self.setPos(pt) |
237 | 225 |
|
238 |
|
|
239 | 226 |
self.update() |
240 | 227 |
|
241 | 228 |
QGraphicsEllipseItem.mouseMoveEvent(self, event) |
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
22 | 22 |
|
23 | 23 |
class QEngineeringLineItem(QGraphicsLineItem, QEngineeringAbstractItem): |
24 | 24 |
ARROW_SIZE = 30 |
25 |
ZVALUE = 100 |
|
25 | 26 |
HIGHLIGHT = '#BC4438' |
26 | 27 |
|
27 | 28 |
''' |
... | ... | |
47 | 48 |
self.setAcceptTouchEvents(True) |
48 | 49 |
|
49 | 50 |
self.transfer = Transfer() |
51 |
self.setZValue(QEngineeringLineItem.ZVALUE) |
|
50 | 52 |
|
51 | 53 |
if vertices: |
52 | 54 |
self.setLine(vertices[0][0], vertices[0][1], vertices[1][0], vertices[1][1]) |
... | ... | |
63 | 65 |
self.connectors.append(connector) |
64 | 66 |
|
65 | 67 |
self.setToolTip('({},{})-({},{})'.format(vertices[0][0], vertices[0][1], vertices[1][0], vertices[1][1])) |
66 |
|
|
67 |
self.setZValue(100) |
|
68 | 68 |
except Exception as ex: |
69 | 69 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
70 | 70 |
|
DTI_PID/DTI_PID/Shapes/EngineeringNozzleItem.py | ||
---|---|---|
12 | 12 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
13 | 13 |
|
14 | 14 |
class QEngineeringNozzleItem(SymbolSvgItem): |
15 |
ZVALUE = 20 |
|
15 | 16 |
clicked = pyqtSignal(QGraphicsSvgItem) |
16 | 17 |
|
17 | 18 |
''' |
... | ... | |
20 | 21 |
SymbolSvgItem.__init__(self, path, uid) |
21 | 22 |
|
22 | 23 |
self._props = [['Name', None], ['Size', None]] |
24 |
self.setZValue(QEngineeringNozzleItem.ZVALUE) |
|
23 | 25 |
|
24 | 26 |
''' |
25 | 27 |
@brief getter of property |
DTI_PID/DTI_PID/Shapes/QEngineeringEquipmentItem.py | ||
---|---|---|
13 | 13 |
|
14 | 14 |
class QEngineeringEquipmentItem(SymbolSvgItem): |
15 | 15 |
clicked = pyqtSignal(QGraphicsSvgItem) |
16 |
ZVALUE = 10 |
|
16 | 17 |
|
17 | 18 |
''' |
18 | 19 |
''' |
19 | 20 |
def __init__(self, path, uid=None): |
20 | 21 |
SymbolSvgItem.__init__(self, path, uid) |
22 |
self.setZValue(QEngineeringEquipmentItem.ZVALUE) |
|
21 | 23 |
|
22 | 24 |
''' |
23 | 25 |
@brief connect attribute |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
18 | 18 |
|
19 | 19 |
class SymbolSvgItem(QGraphicsSvgItem, QEngineeringAbstractItem): |
20 | 20 |
clicked = pyqtSignal(QGraphicsSvgItem) |
21 |
ZVALUE = 50 |
|
21 | 22 |
HIGHLIGHT = '#BC4438' |
22 | 23 |
|
23 | 24 |
''' |
... | ... | |
72 | 73 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
73 | 74 |
finally: |
74 | 75 |
f.close() |
76 |
|
|
77 |
self.setZValue(SymbolSvgItem.ZVALUE) |
|
75 | 78 |
|
76 | 79 |
''' |
77 | 80 |
@breif getter owner |
내보내기 Unified diff