1
|
|
2
|
""" This is stream line item module """
|
3
|
|
4
|
import sys
|
5
|
import os.path
|
6
|
import copy
|
7
|
import numpy as np
|
8
|
|
9
|
try:
|
10
|
from PyQt5.QtCore import *
|
11
|
from PyQt5.QtGui import *
|
12
|
from PyQt5.QtWidgets import *
|
13
|
except ImportError:
|
14
|
try:
|
15
|
from PyQt4.QtCore import Qt, QRectF, QObject, pyqtSignal, QT_VERSION_STR
|
16
|
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QColor
|
17
|
except ImportError:
|
18
|
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
|
19
|
from EngineeringAbstractItem import QEngineeringAbstractItem
|
20
|
|
21
|
|
22
|
class QEngineeringStreamlineItem(QGraphicsPathItem, QEngineeringAbstractItem):
|
23
|
""" This is EngineeringStreamlineItem Class """
|
24
|
|
25
|
ARROW_SIZE = 5
|
26
|
ZVALUE = 50
|
27
|
OFFSET = 10
|
28
|
onRemoved = pyqtSignal(QGraphicsItem)
|
29
|
|
30
|
'''
|
31
|
@history 2018.05.11 Jeongwoo Declare variable self.pen
|
32
|
2018.05.15 Jeongwoo Change method to call parent's __init__
|
33
|
2018.05.25 Jeongwoo Change self.pen's default color (red → blue)
|
34
|
'''
|
35
|
|
36
|
def __init__(self, uid=None, parent=None):
|
37
|
import uuid
|
38
|
from EngineeringStreamNoTextItem import QEngineeringStreamNoTextItem
|
39
|
|
40
|
try:
|
41
|
QGraphicsPathItem.__init__(self, parent)
|
42
|
QEngineeringAbstractItem.__init__(self)
|
43
|
self.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
|
44
|
self.setAcceptHoverEvents(True)
|
45
|
self.setAcceptTouchEvents(True)
|
46
|
|
47
|
self.uid = uuid.uuid4() if uid is None else uid
|
48
|
self.parent = parent
|
49
|
self._vertices = []
|
50
|
self.isCreated = False
|
51
|
self._pt = None
|
52
|
self.setPen(QPen(Qt.blue, 1, Qt.SolidLine))
|
53
|
|
54
|
self._stream_no = 0
|
55
|
self._stream_no_text = None
|
56
|
|
57
|
self._fittings = None
|
58
|
self._mixed_geometry = None
|
59
|
self._pressure_variation = None
|
60
|
|
61
|
self.transfer = Transfer()
|
62
|
self.setZValue(QEngineeringStreamlineItem.ZVALUE)
|
63
|
except Exception as ex:
|
64
|
from App import App
|
65
|
from AppDocData import MessageType
|
66
|
|
67
|
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
68
|
sys.exc_info()[-1].tb_lineno)
|
69
|
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
70
|
|
71
|
def __repr__(self):
|
72
|
""" return string represents stream line item """
|
73
|
return 'Line_{}'.format(self._stream_no)
|
74
|
|
75
|
@property
|
76
|
def fittings(self):
|
77
|
""" return fittings """
|
78
|
return self._fittings
|
79
|
|
80
|
@fittings.setter
|
81
|
def fittings(self, value):
|
82
|
""" set fittings with given value """
|
83
|
self._fittings = value
|
84
|
|
85
|
@property
|
86
|
def mixed_geometry(self):
|
87
|
""" return fittings """
|
88
|
return self._mixed_geometry
|
89
|
|
90
|
@mixed_geometry.setter
|
91
|
def mixed_geometry(self, value):
|
92
|
""" set fittings with given value """
|
93
|
self._mixed_geometry = value
|
94
|
|
95
|
@property
|
96
|
def pressure_variation(self):
|
97
|
return self._pressure_variation
|
98
|
|
99
|
@pressure_variation.setter
|
100
|
def pressure_variation(self, value):
|
101
|
self._pressure_variation = value
|
102
|
|
103
|
@property
|
104
|
def stream_no(self):
|
105
|
""" return stream no """
|
106
|
return self._stream_no
|
107
|
|
108
|
@stream_no.setter
|
109
|
def stream_no(self, value):
|
110
|
""" set stream no with given value """
|
111
|
from EngineeringStreamNoTextItem import QEngineeringStreamNoTextItem
|
112
|
|
113
|
self._stream_no = value
|
114
|
self._stream_no_text = QEngineeringStreamNoTextItem(f"{self._stream_no}", self)
|
115
|
self.build_path()
|
116
|
|
117
|
@property
|
118
|
def data(self):
|
119
|
""" return hmb data"""
|
120
|
from AppDocData import AppDocData
|
121
|
|
122
|
app_doc_data = AppDocData.instance()
|
123
|
return app_doc_data.activeDrawing.hmbTable.get_hmb_data(self.uid)
|
124
|
|
125
|
@property
|
126
|
def density(self):
|
127
|
""" return density """
|
128
|
from AppDocData import AppDocData
|
129
|
|
130
|
res = 0
|
131
|
app_doc_data = AppDocData.instance()
|
132
|
hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(self.uid)
|
133
|
if hmb_data: res = hmb_data.density
|
134
|
|
135
|
return res
|
136
|
|
137
|
@property
|
138
|
def press_drop(self):
|
139
|
""" return press drop """
|
140
|
from AppDocData import AppDocData
|
141
|
|
142
|
app_doc_data = AppDocData.instance()
|
143
|
hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(self.uid)
|
144
|
|
145
|
return hmb_data.pressure_drop if hmb_data else 0
|
146
|
|
147
|
def validate(self):
|
148
|
"""validate stream line data"""
|
149
|
|
150
|
|
151
|
return [[self, 'check the data of mixed type']] if self.data.phase_type == 'Mixed' else None
|
152
|
|
153
|
def build_connectors(self, connected, pointsUids=None):
|
154
|
""" build connectors for stream line
|
155
|
connected is target connector
|
156
|
"""
|
157
|
|
158
|
from SymbolSvgItem import SymbolSvgItem
|
159
|
from EngineeringConnectorItem import QEngineeringConnectorItem
|
160
|
|
161
|
if not self._vertices:
|
162
|
return
|
163
|
|
164
|
targets = []
|
165
|
index = 0
|
166
|
for vertex in [self._vertices[0], self._vertices[-1]]:
|
167
|
if pointsUids:
|
168
|
connector = QEngineeringConnectorItem(pointsUids[index], parent=self, index=index + 1)
|
169
|
else:
|
170
|
connector = QEngineeringConnectorItem(uid=None, parent=self, index=index + 1)
|
171
|
|
172
|
connector.setPos(vertex)
|
173
|
connector.connectPoint = vertex
|
174
|
connector.sceneConnectPoint = vertex
|
175
|
|
176
|
|
177
|
connector.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
|
178
|
connector.setAcceptTouchEvents(True)
|
179
|
connector.transfer.onPosChanged.connect(self.on_connector_pos_changed)
|
180
|
|
181
|
connector.setZValue(self.zValue() + 1)
|
182
|
self.connectors.append(connector)
|
183
|
if len(connected) > index:
|
184
|
connected_item_uid = connected[index]
|
185
|
if connected_item_uid:
|
186
|
target = QEngineeringConnectorItem.find_connector(connected_item_uid)
|
187
|
connector.connect(target)
|
188
|
if target:
|
189
|
target.connect(connector)
|
190
|
targets.append(target)
|
191
|
|
192
|
index = index + 1
|
193
|
|
194
|
""" connect symbol's on_pos_changed signal """
|
195
|
for symbol in [conn.parentItem() for conn in targets if type(conn.parentItem()) is SymbolSvgItem]:
|
196
|
symbol.transfer.on_pos_changed.connect(self.on_symbol_pos_changed)
|
197
|
symbol.transfer.on_size_changed.connect(self.on_symbol_pos_changed)
|
198
|
|
199
|
def update_arrow(self):
|
200
|
""" update flow arrow """
|
201
|
import math
|
202
|
from EngineeringArrowItem import QEngineeringArrowItem
|
203
|
if len(self._vertices) < 2: return
|
204
|
|
205
|
start = self._vertices[-2]
|
206
|
end = self._vertices[-1]
|
207
|
|
208
|
dx = end[0] - start[0]
|
209
|
dy = end[1] - start[1]
|
210
|
length = math.sqrt(dx * dx + dy * dy)
|
211
|
if length == 0: return
|
212
|
|
213
|
_dir = [(end[0] - start[0]) / length, (end[1] - start[1]) / length]
|
214
|
perpendicular = (-_dir[1], _dir[0])
|
215
|
polygon = QPolygonF()
|
216
|
polygon.append(QPointF(end[0] - _dir[0] * QEngineeringStreamlineItem.ARROW_SIZE + perpendicular[
|
217
|
0] * QEngineeringStreamlineItem.ARROW_SIZE * 0.25,
|
218
|
end[1] - _dir[1] * QEngineeringStreamlineItem.ARROW_SIZE + perpendicular[
|
219
|
1] * QEngineeringStreamlineItem.ARROW_SIZE * 0.25))
|
220
|
polygon.append(QPointF(end[0] - _dir[0] * QEngineeringStreamlineItem.ARROW_SIZE - perpendicular[
|
221
|
0] * QEngineeringStreamlineItem.ARROW_SIZE * 0.25,
|
222
|
end[1] - _dir[1] * QEngineeringStreamlineItem.ARROW_SIZE - perpendicular[
|
223
|
1] * QEngineeringStreamlineItem.ARROW_SIZE * 0.25))
|
224
|
polygon.append(QPointF(end[0], end[1]))
|
225
|
polygon.append(polygon[0])
|
226
|
|
227
|
if not hasattr(self, '_arrow'):
|
228
|
self._arrow = QEngineeringArrowItem(polygon, self)
|
229
|
else:
|
230
|
self._arrow.setPolygon(polygon)
|
231
|
|
232
|
self._arrow.setPen(Qt.blue)
|
233
|
self._arrow.setBrush(Qt.blue)
|
234
|
self._arrow.update()
|
235
|
|
236
|
'''
|
237
|
@brief construct a polyline
|
238
|
'''
|
239
|
|
240
|
def process(self, param):
|
241
|
if ('mousePressEvent' == param[0]) and (param[1].button() == Qt.LeftButton):
|
242
|
self._vertices.append(param[2])
|
243
|
elif ('mouseMoveEvent' == param[0]):
|
244
|
self._pt = param[2]
|
245
|
elif ('mouseReleaseEvent' == param[0]) and (param[1].button() == Qt.RightButton):
|
246
|
self.isCreated = True
|
247
|
|
248
|
'''
|
249
|
@brief clone an object
|
250
|
'''
|
251
|
|
252
|
def clone(self):
|
253
|
clone = QEngineeringStreamlineItem()
|
254
|
clone._vertices = copy.deepcopy(self._vertices)
|
255
|
clone.isCreated = self.isCreated
|
256
|
|
257
|
return clone
|
258
|
|
259
|
def init(self):
|
260
|
self._vertices = []
|
261
|
self._pt = None
|
262
|
self.isCreated = False
|
263
|
|
264
|
def set_pressure_variation(self):
|
265
|
from AppDocData import AppDocData
|
266
|
|
267
|
res = []
|
268
|
|
269
|
app_doc_data = AppDocData.instance()
|
270
|
pressure_variation = app_doc_data.get_pressure_variation(self.uid)
|
271
|
'''
|
272
|
for row in pressure_variation:
|
273
|
res.append((row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9],
|
274
|
row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18], row[19]))
|
275
|
'''
|
276
|
|
277
|
self.pressure_variation = pressure_variation
|
278
|
|
279
|
def set_mixed_geometry(self):
|
280
|
from AppDocData import AppDocData
|
281
|
|
282
|
mixed_geometry = []
|
283
|
|
284
|
app_doc_data = AppDocData.instance()
|
285
|
geometry_input = app_doc_data.get_geometry_input(self.uid)
|
286
|
for row in geometry_input:
|
287
|
mixed_geometry.append((row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9]))
|
288
|
|
289
|
self.mixed_geometry = mixed_geometry
|
290
|
|
291
|
def set_fittings(self):
|
292
|
from AppDocData import AppDocData
|
293
|
from Fitting import Fitting
|
294
|
|
295
|
app_doc_data = AppDocData.instance()
|
296
|
fittings_input = app_doc_data.get_fittings_input(self.uid)
|
297
|
|
298
|
fittings = {}
|
299
|
fitting_equivalent_item = []
|
300
|
fitting_crane_k_item = []
|
301
|
fitting_2_k_item = []
|
302
|
|
303
|
for fitting in fittings_input:
|
304
|
uid = fitting[0]
|
305
|
method = fitting[1]
|
306
|
sub_size = fitting[2]
|
307
|
angle = fitting[3]
|
308
|
count = fitting[4]
|
309
|
|
310
|
if method == 'Equivalent_Length':
|
311
|
fitting_equivalent_item.append(Fitting(uid, sub_size, angle, count))
|
312
|
fittings[method] = fitting_equivalent_item
|
313
|
elif method == 'CraneK':
|
314
|
fitting_crane_k_item.append(Fitting(uid, sub_size, angle, count))
|
315
|
fittings[method] = fitting_crane_k_item
|
316
|
elif method == '2-K':
|
317
|
fitting_2_k_item.append(Fitting(uid, sub_size, angle, count))
|
318
|
fittings[method] = fitting_2_k_item
|
319
|
|
320
|
self.fittings = fittings
|
321
|
|
322
|
def build_path(self):
|
323
|
"""build path"""
|
324
|
if not self._vertices or len(self._vertices) < 2:
|
325
|
return
|
326
|
|
327
|
try:
|
328
|
if self.connectors:
|
329
|
|
330
|
self._vertices = []
|
331
|
|
332
|
self._vertices.append(self.connectors[0].center())
|
333
|
dx = self.connectors[-1].center()[0] - self._vertices[0][0]
|
334
|
dy = self.connectors[-1].center()[1] - self._vertices[0][1]
|
335
|
if (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'DOWN') and \
|
336
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'LEFT'):
|
337
|
if dx >= 0 and dy > 0:
|
338
|
self._vertices.append((self._vertices[0][0], self._vertices[0][1] + dy))
|
339
|
elif dx < 0 <= dy:
|
340
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
341
|
self._vertices.append(
|
342
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
343
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
344
|
elif dx < 0 and dy < 0:
|
345
|
self._vertices.append(
|
346
|
(self._vertices[0][0], self._vertices[-1][1] + QEngineeringStreamlineItem.OFFSET))
|
347
|
self._vertices.append(
|
348
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
349
|
self._vertices.append(
|
350
|
(self._vertices[-1][0], self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
351
|
elif dx > 0 > dy:
|
352
|
self._vertices.append(
|
353
|
(self._vertices[0][0], self._vertices[0][1] + QEngineeringStreamlineItem.OFFSET))
|
354
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
355
|
self._vertices.append((self._vertices[-1][0], self.connectors[-1].center()[1]))
|
356
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'DOWN') and \
|
357
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'RIGHT'):
|
358
|
if dx >= 0 and dy < 0:
|
359
|
self._vertices.append(
|
360
|
(self._vertices[-1][0], self._vertices[-1][1] + QEngineeringStreamlineItem.OFFSET))
|
361
|
self._vertices.append(
|
362
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
363
|
self._vertices.append((self._vertices[-1][0],
|
364
|
self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
365
|
elif dx < 0 and dy < 0:
|
366
|
self._vertices.append(
|
367
|
(self._vertices[-1][0], self._vertices[-1][1] + QEngineeringStreamlineItem.OFFSET))
|
368
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
369
|
self._vertices.append(
|
370
|
(self._vertices[-1][0], self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
371
|
elif dx < 0 and dy >= 0:
|
372
|
self._vertices.append((self._vertices[0][0], self._vertices[-1][1] + dy))
|
373
|
elif dx >= 0 and dy >= 0:
|
374
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
375
|
self._vertices.append(
|
376
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
377
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
378
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'DOWN') and \
|
379
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'UP'):
|
380
|
if dx >= 0 and dy < 0:
|
381
|
self._vertices.append(
|
382
|
(self._vertices[-1][0], self._vertices[-1][1] + QEngineeringStreamlineItem.OFFSET))
|
383
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
384
|
self._vertices.append((self._vertices[-1][0],
|
385
|
self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET * 2))
|
386
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
387
|
elif dx < 0 and dy < 0:
|
388
|
self._vertices.append(
|
389
|
(self._vertices[-1][0], self._vertices[-1][1] + QEngineeringStreamlineItem.OFFSET))
|
390
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
391
|
self._vertices.append((self._vertices[-1][0],
|
392
|
self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET * 2))
|
393
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
394
|
elif dx < 0 and dy >= 0:
|
395
|
self._vertices.append((self._vertices[0][0], self._vertices[-1][1] + dy * 0.5))
|
396
|
self._vertices.append((self._vertices[0][0] + dx, self._vertices[-1][1]))
|
397
|
elif dx >= 0 and dy >= 0:
|
398
|
self._vertices.append((self._vertices[0][0], self._vertices[-1][1] + dy * 0.5))
|
399
|
self._vertices.append((self._vertices[0][0] + dx, self._vertices[-1][1]))
|
400
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'DOWN') and \
|
401
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'DOWN'):
|
402
|
if dx >= 0 and dy < 0:
|
403
|
self._vertices.append(
|
404
|
(self._vertices[-1][0], self._vertices[-1][1] + QEngineeringStreamlineItem.OFFSET))
|
405
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
406
|
elif dx < 0 and dy < 0:
|
407
|
self._vertices.append(
|
408
|
(self._vertices[-1][0], self._vertices[-1][1] + QEngineeringStreamlineItem.OFFSET))
|
409
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
410
|
elif dx < 0 and dy >= 0:
|
411
|
self._vertices.append(
|
412
|
(self._vertices[0][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
413
|
self._vertices.append((self._vertices[0][0] + dx, self._vertices[-1][1]))
|
414
|
elif dx >= 0 and dy >= 0:
|
415
|
self._vertices.append(
|
416
|
(self._vertices[0][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
417
|
self._vertices.append((self._vertices[0][0] + dx, self._vertices[-1][1]))
|
418
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'UP') and \
|
419
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'LEFT'):
|
420
|
if dx >= 0 and dy < 0:
|
421
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
422
|
elif dx >= 0 and dy >= 0:
|
423
|
self._vertices.append(
|
424
|
(self._vertices[-1][0], self._vertices[-1][1] - QEngineeringStreamlineItem.OFFSET))
|
425
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
426
|
self._vertices.append(
|
427
|
(self._vertices[-1][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
428
|
elif dx < 0 and dy >= 0:
|
429
|
self._vertices.append(
|
430
|
(self._vertices[-1][0], self._vertices[-1][1] - QEngineeringStreamlineItem.OFFSET))
|
431
|
self._vertices.append(
|
432
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
433
|
self._vertices.append(
|
434
|
(self._vertices[-1][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
435
|
else:
|
436
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
437
|
self._vertices.append(
|
438
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
439
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
440
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'UP') and \
|
441
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'RIGHT'):
|
442
|
if dx >= 0 and dy < 0:
|
443
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
444
|
self._vertices.append(
|
445
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
446
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
447
|
elif dx < 0 and dy < 0:
|
448
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
449
|
elif dx < 0 and dy >= 0:
|
450
|
self._vertices.append(
|
451
|
(self._vertices[-1][0], self._vertices[-1][1] - QEngineeringStreamlineItem.OFFSET))
|
452
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
453
|
self._vertices.append(
|
454
|
(self._vertices[-1][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
455
|
else:
|
456
|
self._vertices.append(
|
457
|
(self._vertices[-1][0], self._vertices[-1][1] - QEngineeringStreamlineItem.OFFSET))
|
458
|
self._vertices.append(
|
459
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
460
|
self._vertices.append(
|
461
|
(self._vertices[-1][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
462
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'UP') and \
|
463
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'DOWN'):
|
464
|
if dy < 0:
|
465
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
466
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
467
|
else:
|
468
|
self._vertices.append(
|
469
|
(self._vertices[-1][0], self._vertices[-1][1] - QEngineeringStreamlineItem.OFFSET))
|
470
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
471
|
self._vertices.append((self._vertices[-1][0],
|
472
|
self.connectors[-1].center()[1] + QEngineeringStreamlineItem.OFFSET))
|
473
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
474
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'UP') and \
|
475
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'UP'):
|
476
|
if dx >= 0 and dy < 0:
|
477
|
self._vertices.append(
|
478
|
(self._vertices[-1][0], self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
479
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
480
|
elif dx < 0 and dy < 0:
|
481
|
self._vertices.append(
|
482
|
(self._vertices[-1][0], self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
483
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
484
|
elif dx < 0 and dy >= 0:
|
485
|
self._vertices.append(
|
486
|
(self._vertices[-1][0], self._vertices[-1][1] - QEngineeringStreamlineItem.OFFSET))
|
487
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
488
|
else:
|
489
|
self._vertices.append(
|
490
|
(self._vertices[-1][0], self._vertices[-1][1] - QEngineeringStreamlineItem.OFFSET))
|
491
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
492
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'RIGHT') and \
|
493
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'LEFT'):
|
494
|
if dx >= 0:
|
495
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
496
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
497
|
else:
|
498
|
self._vertices.append(
|
499
|
(self._vertices[-1][0] + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
500
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
501
|
self._vertices.append((self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET * 2,
|
502
|
self._vertices[-1][1]))
|
503
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
504
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'RIGHT') and \
|
505
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'DOWN'):
|
506
|
if dx >= 0 and dy < 0:
|
507
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
508
|
elif dx < 0 and dy < 0:
|
509
|
self._vertices.append(
|
510
|
(self._vertices[-1][0] + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
511
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
512
|
self._vertices.append(
|
513
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
514
|
elif dx < 0 and dy >= 0:
|
515
|
self._vertices.append(
|
516
|
(self._vertices[-1][0] + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
517
|
self._vertices.append(
|
518
|
(self._vertices[-1][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
519
|
self._vertices.append(
|
520
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
521
|
else:
|
522
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
523
|
self._vertices.append(
|
524
|
(self._vertices[-1][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
525
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
526
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'RIGHT') and \
|
527
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'UP'):
|
528
|
if dx >= 0 and dy < 0:
|
529
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
530
|
self._vertices.append(
|
531
|
(self._vertices[-1][0], self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
532
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
533
|
elif dx < 0 and dy < 0:
|
534
|
self._vertices.append(
|
535
|
(self._vertices[-1][0] + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
536
|
self._vertices.append(
|
537
|
(self._vertices[-1][0], self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
538
|
self._vertices.append(
|
539
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
540
|
elif dx < 0 and dy >= 0:
|
541
|
self._vertices.append(
|
542
|
(self._vertices[-1][0] + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
543
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
544
|
self._vertices.append(
|
545
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
546
|
else:
|
547
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
548
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'RIGHT') and \
|
549
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'RIGHT'):
|
550
|
if dx >= 0 and dy < 0:
|
551
|
self._vertices.append(
|
552
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
553
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
554
|
elif dx < 0 and dy < 0:
|
555
|
self._vertices.append(
|
556
|
(self._vertices[-1][0] + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
557
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
558
|
elif dx < 0 and dy >= 0:
|
559
|
self._vertices.append(
|
560
|
(self._vertices[-1][0] + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
561
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
562
|
else:
|
563
|
self._vertices.append(
|
564
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
565
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
566
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'LEFT') and \
|
567
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'LEFT'):
|
568
|
if dx >= 0 and dy < 0:
|
569
|
self._vertices.append(
|
570
|
(self._vertices[-1][0] - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
571
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
572
|
elif dx < 0 and dy < 0:
|
573
|
self._vertices.append(
|
574
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
575
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
576
|
elif dx < 0 and dy >= 0:
|
577
|
self._vertices.append(
|
578
|
(self._vertices[-1][0] + dx - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
579
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
580
|
else:
|
581
|
self._vertices.append(
|
582
|
(self._vertices[-1][0] - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
583
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
584
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'LEFT') and \
|
585
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'RIGHT'):
|
586
|
if dx >= 0 and dy < 0:
|
587
|
self._vertices.append(
|
588
|
(self._vertices[-1][0] - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
589
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
590
|
self._vertices.append(
|
591
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET * 2, self._vertices[-1][1]))
|
592
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
593
|
elif dx < 0 and dy < 0:
|
594
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
595
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
596
|
elif dx < 0 and dy >= 0:
|
597
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
598
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
599
|
else:
|
600
|
self._vertices.append(
|
601
|
(self._vertices[-1][0] - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
602
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
603
|
self._vertices.append(
|
604
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET * 2, self._vertices[-1][1]))
|
605
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
606
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'LEFT') and \
|
607
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'UP'):
|
608
|
if dx >= 0 and dy < 0:
|
609
|
self._vertices.append(
|
610
|
(self._vertices[-1][0] - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
611
|
self._vertices.append(
|
612
|
(self._vertices[-1][0], self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
613
|
self._vertices.append(
|
614
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
615
|
elif dx < 0 and dy < 0:
|
616
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
617
|
self._vertices.append(
|
618
|
(self._vertices[-1][0], self._vertices[-1][1] + dy - QEngineeringStreamlineItem.OFFSET))
|
619
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
620
|
elif dx < 0 and dy >= 0:
|
621
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
622
|
else:
|
623
|
self._vertices.append(
|
624
|
(self._vertices[-1][0] - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
625
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
626
|
self._vertices.append(
|
627
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
628
|
elif (self.connectors[0].connectedItem and self.connectors[0].connectedItem.direction == 'LEFT') and \
|
629
|
(self.connectors[-1].connectedItem and self.connectors[-1].connectedItem.direction == 'DOWN'):
|
630
|
if dx >= 0 and dy < 0:
|
631
|
self._vertices.append(
|
632
|
(self._vertices[-1][0] - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
633
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy * 0.5))
|
634
|
self._vertices.append(
|
635
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
636
|
elif dx < 0 and dy < 0:
|
637
|
self._vertices.append((self._vertices[-1][0] + dx, self._vertices[-1][1]))
|
638
|
elif dx < 0 and dy >= 0:
|
639
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
640
|
self._vertices.append(
|
641
|
(self._vertices[-1][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
642
|
self._vertices.append((self._vertices[-1][0] + dx * 0.5, self._vertices[-1][1]))
|
643
|
else:
|
644
|
self._vertices.append(
|
645
|
(self._vertices[-1][0] - QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
646
|
self._vertices.append(
|
647
|
(self._vertices[-1][0], self._vertices[-1][1] + dy + QEngineeringStreamlineItem.OFFSET))
|
648
|
self._vertices.append(
|
649
|
(self._vertices[-1][0] + dx + QEngineeringStreamlineItem.OFFSET, self._vertices[-1][1]))
|
650
|
else:
|
651
|
self._vertices.append((self._vertices[0][0] + dx * 0.5, self._vertices[0][1]))
|
652
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
653
|
|
654
|
self._vertices.append(self.connectors[-1].center())
|
655
|
|
656
|
|
657
|
path = QPainterPath()
|
658
|
path.moveTo(self._vertices[0][0], self._vertices[0][1])
|
659
|
|
660
|
max_length = 0
|
661
|
max_length_line = [None, None]
|
662
|
for i in range(1, len(self._vertices)):
|
663
|
path.lineTo(self._vertices[i][0], self._vertices[i][1])
|
664
|
dx = self._vertices[i][0] - self._vertices[i - 1][0]
|
665
|
dy = self._vertices[i][1] - self._vertices[i - 1][1]
|
666
|
if dx * dx + dy * dy > max_length:
|
667
|
max_length = dx * dx + dy * dy
|
668
|
max_length_line[0] = self._vertices[i - 1]
|
669
|
max_length_line[1] = self._vertices[i]
|
670
|
|
671
|
self.setPath(path)
|
672
|
self.isCreated = True
|
673
|
|
674
|
if self._stream_no_text:
|
675
|
doc = self._stream_no_text.document()
|
676
|
option = doc.defaultTextOption()
|
677
|
option.setAlignment(Qt.AlignCenter)
|
678
|
doc.setDefaultTextOption(option)
|
679
|
if max_length_line[0] is not None and max_length_line[1] is not None:
|
680
|
self._stream_no_text.setTextWidth(doc.idealWidth())
|
681
|
dx = max_length_line[0][0] - max_length_line[1][0]
|
682
|
dy = max_length_line[0][1] - max_length_line[1][1]
|
683
|
if abs(dx) >= abs(dy):
|
684
|
x = (max_length_line[0][0] + max_length_line[1][0] - self._stream_no_text.textWidth()) * 0.5
|
685
|
y = (max_length_line[0][1] + max_length_line[1][1]) * 0.5
|
686
|
self._stream_no_text.setPos(QPointF(x, y))
|
687
|
else:
|
688
|
x = (max_length_line[0][0] + max_length_line[1][0]) * 0.5
|
689
|
y = (max_length_line[0][1] + max_length_line[1][1] - self._stream_no_text.textWidth()) * 0.5
|
690
|
self._stream_no_text.setPos(QPointF(x, y))
|
691
|
|
692
|
self.update_arrow()
|
693
|
except Exception as ex:
|
694
|
from App import App
|
695
|
from AppDocData import MessageType
|
696
|
|
697
|
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
698
|
sys.exc_info()[-1].tb_lineno)
|
699
|
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
700
|
|
701
|
'''
|
702
|
@brief return bounding rectangle of polyline
|
703
|
@author humkyung
|
704
|
@date 2018.07.23
|
705
|
'''
|
706
|
|
707
|
def boundingRect(self):
|
708
|
rect = QRectF()
|
709
|
|
710
|
if self.isCreated:
|
711
|
rect = self.path().boundingRect()
|
712
|
rect = QRectF(rect.left() - 5, rect.top() - 5, rect.width() + 10, rect.height() + 10)
|
713
|
else:
|
714
|
minX = None
|
715
|
minY = None
|
716
|
maxX = None
|
717
|
maxY = None
|
718
|
for pt in self._vertices:
|
719
|
if minX is None or pt[0] < minX:
|
720
|
minX = pt[0]
|
721
|
if minY is None or pt[1] < minY:
|
722
|
minY = pt[1]
|
723
|
|
724
|
if maxX is None or pt[0] > maxX:
|
725
|
maxX = pt[0]
|
726
|
if maxY is None or pt[1] > maxY:
|
727
|
maxY = pt[1]
|
728
|
|
729
|
if self._pt is not None:
|
730
|
if minX is None or self._pt[0] < minX:
|
731
|
minX = self._pt[0]
|
732
|
if minY is None or self._pt[1] < minY:
|
733
|
minY = self._pt[1]
|
734
|
|
735
|
if maxX is None or self._pt[0] > maxX:
|
736
|
maxX = self._pt[0]
|
737
|
if maxY is None or self._pt[1] > maxY:
|
738
|
maxY = self._pt[1]
|
739
|
|
740
|
if minX is not None and minY is not None and maxX is not None and maxY is not None:
|
741
|
rect = QRectF(minX - 5, minY - 5, maxX - minX + 10, maxY - minY + 10)
|
742
|
|
743
|
return rect
|
744
|
|
745
|
'''
|
746
|
@brief
|
747
|
@author humkyung
|
748
|
@date 2018.07.26
|
749
|
'''
|
750
|
|
751
|
def onMouseMoved(self, event, scenePos):
|
752
|
from SymbolSvgItem import SymbolSvgItem
|
753
|
from EngineeringConnectorItem import QEngineeringConnectorItem
|
754
|
|
755
|
|
756
|
pt = (scenePos.x(), scenePos.y())
|
757
|
item = self.scene().itemAt(scenePos, QTransform())
|
758
|
if (item is not None) and (type(item) is SymbolSvgItem):
|
759
|
connPt = item.getConnectionPointCloseTo(pt, 5)
|
760
|
if connPt is not None: pt = connPt
|
761
|
elif (item is not None) and (type(item) is QEngineeringConnectorItem):
|
762
|
pt = item.center()
|
763
|
|
764
|
|
765
|
del self._vertices[1:]
|
766
|
dx = pt[0] - self._vertices[0][0]
|
767
|
dy = pt[1] - self._vertices[0][1]
|
768
|
self._vertices.append((self._vertices[0][0] + dx * 0.5, self._vertices[0][1]))
|
769
|
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
|
770
|
self._vertices.append(pt)
|
771
|
|
772
|
self.build_path()
|
773
|
self.update()
|
774
|
|
775
|
def hoverEnterEvent(self, event):
|
776
|
""" hilight item and it's children """
|
777
|
self.highlight(True)
|
778
|
|
779
|
def hoverLeaveEvent(self, event):
|
780
|
""" unhighlight item """
|
781
|
self.highlight(False)
|
782
|
|
783
|
def highlight(self, flag):
|
784
|
self.hover = flag
|
785
|
self.setZValue(QEngineeringAbstractItem.HOVER_ZVALUE) if flag else \
|
786
|
self.setZValue(QEngineeringStreamlineItem.ZVALUE)
|
787
|
self.update()
|
788
|
|
789
|
def paint(self, painter, option, widget):
|
790
|
""" override paint method """
|
791
|
if self.isSelected():
|
792
|
hilightColor = QColor(255, 0, 0, 127)
|
793
|
focuspen = QPen(Qt.DotLine)
|
794
|
focuspen.setColor(hilightColor)
|
795
|
focuspen.setWidthF(3)
|
796
|
painter.setPen(focuspen)
|
797
|
painter.drawPath(self.path())
|
798
|
else:
|
799
|
color = '#FF0000' if self.validate() else self.getColor()
|
800
|
self.setColor(color)
|
801
|
QGraphicsPathItem.paint(self, painter, option, widget)
|
802
|
|
803
|
'''
|
804
|
@brief Return real item position
|
805
|
@authro Jeongwoo
|
806
|
@date 2018.05.29
|
807
|
'''
|
808
|
|
809
|
def boundingRectOnScene(self):
|
810
|
rect = self.boundingRect()
|
811
|
sp = self.startPoint()
|
812
|
rect.moveTo(sp[0], sp[1])
|
813
|
return rect
|
814
|
|
815
|
'''
|
816
|
@brief Set Color. Override QEngineeringAbstractItem's
|
817
|
@author Jeongwoo
|
818
|
@date 2018.05.11
|
819
|
@history 2018.05.11 Jeongwoo Add self.setPen() Method
|
820
|
@history humkyung 2018.05.13 call setPen method to apply changed color
|
821
|
'''
|
822
|
|
823
|
def setColor(self, color):
|
824
|
c = QColor()
|
825
|
c.setNamedColor(color)
|
826
|
_pen = self.pen()
|
827
|
_pen.setColor(c)
|
828
|
self.setPen(_pen)
|
829
|
self.update()
|
830
|
|
831
|
def on_symbol_pos_changed(self, symbol):
|
832
|
""" rebuild stream line because symbol position is changed """
|
833
|
if self.connectors[0].connectedItem is not None:
|
834
|
self.connectors[0].setPos(self.connectors[0].connectedItem.center())
|
835
|
if self.connectors[-1].connectedItem is not None:
|
836
|
self.connectors[-1].setPos(self.connectors[-1].connectedItem.center())
|
837
|
self.on_connector_pos_changed(None)
|
838
|
|
839
|
def on_connector_pos_changed(self, connector):
|
840
|
""" rebuild stream line """
|
841
|
|
842
|
self.build_path()
|
843
|
self.update()
|
844
|
self.scene().contents_changed.emit()
|
845
|
|
846
|
def mouseDoubleClickEvent(self, event):
|
847
|
from StreamDataDialog import QStreamDataDialog
|
848
|
try:
|
849
|
|
850
|
dialog = QStreamDataDialog()
|
851
|
res = dialog.showDialog(self)
|
852
|
if res:
|
853
|
self.load_HMB()
|
854
|
|
855
|
except Exception as ex:
|
856
|
from App import App
|
857
|
from AppDocData import MessageType
|
858
|
|
859
|
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
860
|
sys.exc_info()[-1].tb_lineno)
|
861
|
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
862
|
|
863
|
def load_HMB(self):
|
864
|
from App import App
|
865
|
|
866
|
App.mainWnd().load_HMB()
|
867
|
|
868
|
def keyPressEvent(self, event):
|
869
|
from App import App
|
870
|
from AppDocData import AppDocData
|
871
|
if not self.isSelected(): return
|
872
|
|
873
|
if event.key() == Qt.Key_Delete:
|
874
|
self.transfer.onRemoved.emit(self)
|
875
|
elif event.key() == Qt.Key_QuoteLeft:
|
876
|
self.mouseDoubleClickEvent(event)
|
877
|
|
878
|
def toSql(self):
|
879
|
""" convert valve data to sql query """
|
880
|
import uuid
|
881
|
from AppDocData import AppDocData
|
882
|
|
883
|
res = []
|
884
|
app_doc_data = AppDocData.instance()
|
885
|
|
886
|
try:
|
887
|
symbolInfo = app_doc_data.getSymbolByQuery('name', 'Stream Line')
|
888
|
dbUid = symbolInfo.uid
|
889
|
uid = self.uid
|
890
|
|
891
|
cols = ['UID', 'Symbols_UID', 'Name']
|
892
|
values = ['?', '?', '?']
|
893
|
param = [str(uid), str(dbUid), str(self.stream_no)]
|
894
|
sql = 'insert or replace into Components({}) values({})'.format(','.join(cols), ','.join(values))
|
895
|
res.append((sql, tuple(param)))
|
896
|
|
897
|
|
898
|
index = 1
|
899
|
for vertex in self._vertices:
|
900
|
if index == 1 and self.connectors[0].connectedItem is not None:
|
901
|
cols = ['UID', 'Components_UID', '[Index]', 'X', 'Y', 'ConnectedItem_UID']
|
902
|
values = ['?', '?', '?', '?', '?', '?']
|
903
|
param = [str(uuid.uuid4()), str(uid), index, vertex[0], vertex[1],
|
904
|
str(self.connectors[0].connectedItem.uid)]
|
905
|
elif index == len(self._vertices) and self.connectors[1].connectedItem is not None:
|
906
|
cols = ['UID', 'Components_UID', '[Index]', 'X', 'Y', 'ConnectedItem_UID']
|
907
|
values = ['?', '?', '?', '?', '?', '?']
|
908
|
param = [str(uuid.uuid4()), str(uid), index, vertex[0], vertex[1],
|
909
|
str(self.connectors[1].connectedItem.uid)]
|
910
|
else:
|
911
|
cols = ['UID', 'Components_UID', '[Index]', 'X', 'Y']
|
912
|
values = ['?', '?', '?', '?', '?']
|
913
|
param = [str(uuid.uuid4()), str(uid), index, vertex[0], vertex[1]]
|
914
|
|
915
|
sql = 'insert or replace into Points({}) values({})'.format(','.join(cols), ','.join(values))
|
916
|
|
917
|
res.append((sql, tuple(param)))
|
918
|
index += 1
|
919
|
|
920
|
if self.fittings:
|
921
|
for method in self.fittings:
|
922
|
cols = ['UID', 'Components_UID', 'Fittings_UID', 'Method', 'Sub_Size', 'Angle', 'Count']
|
923
|
values = ['?', '?', '?', '?', '?', '?', '?']
|
924
|
|
925
|
for fitting in self.fittings[method]:
|
926
|
param = [str(uuid.uuid4()), str(uid), fitting.uid, method, fitting.sub_size, fitting.angle,
|
927
|
fitting.count]
|
928
|
|
929
|
sql = 'insert or replace into Fittings_Input({}) values({})'.format(','.join(cols),
|
930
|
','.join(values))
|
931
|
res.append((sql, tuple(param)))
|
932
|
|
933
|
|
934
|
if self.mixed_geometry:
|
935
|
for row in self.mixed_geometry:
|
936
|
cols = ['UID', 'Components_UID', 'Element', 'Nominal_Pipe_Size', 'Schedule_No', 'Inside_Pipe_Size',
|
937
|
'Roughness', 'Length', 'Angle', 'RPD', 'D1_D2', 'k']
|
938
|
values = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?']
|
939
|
|
940
|
param = [str(uuid.uuid4()), str(uid), row[0], row[1], row[2], row[3], row[4], row[5], row[6],
|
941
|
row[7], row[8], row[9]]
|
942
|
|
943
|
sql = 'insert or replace into Geometry_Input({}) values({})'.format(','.join(cols),
|
944
|
','.join(values))
|
945
|
res.append((sql, tuple(param)))
|
946
|
|
947
|
|
948
|
if self.pressure_variation:
|
949
|
for row in self.pressure_variation:
|
950
|
cols = ['UID', 'Components_UID', 'Element', 'Inside_Pipe_Size', 'Length', 'Angle', 'K', 'Pressure',
|
951
|
'Void', 'Quality', 'Density', 'V_Den', 'Mean_Vel', 'Max_Vel', 'Ero_Vel', 'Pattern_X',
|
952
|
'Pattern_Y', 'Regime', 'Friction', 'Gravity', 'Momentum', 'Total']
|
953
|
values = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
|
954
|
'?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?']
|
955
|
|
956
|
param = [str(uuid.uuid4()), str(uid), str(row[0]), row[1], row[2], row[3], row[4], row[5], row[6],
|
957
|
row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14], row[15], row[16],
|
958
|
row[17], row[18], row[19]]
|
959
|
|
960
|
sql = 'insert or replace into PressureVariation({}) values({})'.format(','.join(cols),
|
961
|
','.join(values))
|
962
|
res.append((sql, tuple(param)))
|
963
|
|
964
|
except Exception as ex:
|
965
|
from App import App
|
966
|
from AppDocData import MessageType
|
967
|
|
968
|
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
969
|
sys.exc_info()[-1].tb_lineno)
|
970
|
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
971
|
|
972
|
return res
|
973
|
|
974
|
@staticmethod
|
975
|
def fromDatabase(componentInfos):
|
976
|
from AppDocData import AppDocData
|
977
|
|
978
|
item = None
|
979
|
try:
|
980
|
app_doc_data = AppDocData.instance()
|
981
|
|
982
|
uid = componentInfos[0]['Comp_UID']
|
983
|
|
984
|
item = QEngineeringStreamlineItem(uid)
|
985
|
hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(uid)
|
986
|
item.stream_no = int(hmb_data.stream_no) if hmb_data else 1
|
987
|
|
988
|
pointsUids = []
|
989
|
for componentInfo in componentInfos:
|
990
|
pointsUid = componentInfo['Point_UID']
|
991
|
x = componentInfo['X']
|
992
|
y = componentInfo['Y']
|
993
|
|
994
|
pointsUids.append(pointsUid)
|
995
|
item._vertices.append((x, y))
|
996
|
|
997
|
connectorItems = [componentInfos[0]['ConnectedItem_UID'], componentInfos[-1]['ConnectedItem_UID']]
|
998
|
|
999
|
item.setVisible(False)
|
1000
|
item.build_connectors(connectorItems, pointsUids)
|
1001
|
item.build_path()
|
1002
|
item.set_fittings()
|
1003
|
item.set_mixed_geometry()
|
1004
|
item.set_pressure_variation()
|
1005
|
item.update()
|
1006
|
|
1007
|
except Exception as ex:
|
1008
|
from App import App
|
1009
|
from AppDocData import MessageType
|
1010
|
|
1011
|
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
1012
|
sys.exc_info()[-1].tb_lineno)
|
1013
|
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
1014
|
|
1015
|
return item
|
1016
|
|
1017
|
|
1018
|
'''
|
1019
|
@brief The class transfer pyqtSignal Event. Cause Subclass of QGraphicsRectItem can't use pyqtSignal
|
1020
|
@author Jeongwoo
|
1021
|
@date 2018.06.18
|
1022
|
'''
|
1023
|
|
1024
|
|
1025
|
class Transfer(QObject):
|
1026
|
onRemoved = pyqtSignal(QGraphicsItem)
|
1027
|
|
1028
|
def __init__(self, parent=None):
|
1029
|
QObject.__init__(self, parent)
|