개정판 42176339
issue #622:
- 연결 객체를 담는 컨테이너 변경
DTI_PID/DTI_PID/Commands/SelectAttributeCommand.py | ||
---|---|---|
1 | 1 |
import os.path |
2 |
import sys |
|
2 | 3 |
import AbstractCommand |
4 |
|
|
3 | 5 |
try: |
4 | 6 |
from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent |
5 | 7 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QCursor, QMouseEvent, QTransform |
... | ... | |
37 | 39 |
event = param[1] |
38 | 40 |
scenePos = param[2] |
39 | 41 |
|
40 |
if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton: |
|
41 |
from SymbolSvgItem import SymbolSvgItem |
|
42 |
from EngineeringTextItem import QEngineeringTextItem |
|
43 |
from EngineeringLineItem import QEngineeringLineItem |
|
44 |
if self._attr is not None: |
|
45 |
item = self.imageViewer.scene.itemAt(scenePos, QTransform()) |
|
46 |
if item is not None and self._attr.AttributeType == 'Text Item' and type(item) is QEngineeringTextItem: |
|
47 |
self._item.removeSelfAttr(self._attr.UID) |
|
48 |
item.attribute = self._attr.UID |
|
49 |
|
|
50 |
# 기존 연결되있는 다른 SymbolItem의 Attr 제거 |
|
51 |
self._item.removeAttr(item) |
|
52 |
# add attr |
|
53 |
self._item.attrs.append(item) |
|
54 |
|
|
55 |
# _texts 검사 |
|
56 |
while len(self._item._texts) <= self._attr.AttrAt: |
|
57 |
self._item._texts.append(None) |
|
58 |
self._item._texts[self._attr.AttrAt] = item |
|
59 |
|
|
60 |
self.onSuccess.emit() |
|
61 |
elif item is not None and self._attr.AttributeType == 'Symbol Item' and issubclass(type(item), SymbolSvgItem): |
|
62 |
self._item.removeSelfAttr(self._attr.UID) |
|
63 |
item.attribute = self._attr.UID |
|
64 |
|
|
65 |
# 기존 연결되있는 다른 SymbolItem의 Attr 제거 |
|
66 |
self._item.removeAttr(item) |
|
67 |
# add attr |
|
68 |
self._item.attrs.append(item) |
|
69 |
|
|
70 |
# _symbols 검사 |
|
71 |
while len(self._item._symbols) <= self._attr.AttrAt: |
|
72 |
self._item._symbols.append(None) |
|
73 |
self._item._symbols[self._attr.AttrAt] = item |
|
74 |
|
|
75 |
self.onSuccess.emit() |
|
76 |
elif item is not None and self._attr.AttributeType == 'Line Item' and issubclass(type(item), QEngineeringLineItem): |
|
77 |
self._item.conns.clear() |
|
78 |
self._item.conns.append(item) |
|
79 |
|
|
80 |
self.onSuccess.emit() |
|
81 |
elif item is not None and self._attr.AttributeType == 'Line Conn' and issubclass(type(item), QEngineeringLineItem): |
|
82 |
self._item.connectors[self._attr.ConnNum - 1].connectedItem = item |
|
83 |
|
|
84 |
self.onSuccess.emit() |
|
85 |
|
|
42 |
try: |
|
43 |
if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton: |
|
44 |
from SymbolSvgItem import SymbolSvgItem |
|
45 |
from EngineeringTextItem import QEngineeringTextItem |
|
46 |
from EngineeringLineItem import QEngineeringLineItem |
|
47 |
|
|
48 |
if self._attr is not None: |
|
49 |
item = self.imageViewer.scene.itemAt(scenePos, QTransform()) |
|
50 |
if item is not None and self._attr.AttributeType == 'Text Item' and issubclass(type(item), QEngineeringTextItem): |
|
51 |
self._item.removeSelfAttr(self._attr.UID) |
|
52 |
|
|
53 |
# 기존 연결되있는 다른 SymbolItem의 Attr 제거 |
|
54 |
self._item.removeAttr(item) |
|
55 |
|
|
56 |
# _texts 검사 |
|
57 |
while len(self._item._associations[self._attr.AttributeType]) <= self._attr.AttrAt: |
|
58 |
self._item._associations[self._attr.AttributeType].append(None) |
|
59 |
self._item._associations[self._attr.AttributeType][self._attr.AttrAt] = item |
|
60 |
|
|
61 |
self.onSuccess.emit() |
|
62 |
elif item is not None and self._attr.AttributeType == 'Symbol Item' and issubclass(type(item), SymbolSvgItem): |
|
63 |
self._item.removeSelfAttr(self._attr.UID) |
|
64 |
|
|
65 |
# 기존 연결되있는 다른 SymbolItem의 Attr 제거 |
|
66 |
self._item.removeAttr(item) |
|
67 |
|
|
68 |
# _symbols 검사 |
|
69 |
while len(self._item._associations[self._attr.AttributeType]) <= self._attr.AttrAt: |
|
70 |
self._item._associations[self._attr.AttributeType].append(None) |
|
71 |
self._item._associations[self._attr.AttributeType][self._attr.AttrAt] = item |
|
72 |
|
|
73 |
self.onSuccess.emit() |
|
74 |
elif item is not None and self._attr.AttributeType == 'Line Item' and issubclass(type(item), QEngineeringLineItem): |
|
75 |
self._item.conns.clear() |
|
76 |
self._item.conns.append(item) |
|
77 |
|
|
78 |
self.onSuccess.emit() |
|
79 |
elif item is not None and self._attr.AttributeType == 'Line Conn' and issubclass(type(item), QEngineeringLineItem): |
|
80 |
self._item.connectors[self._attr.ConnNum - 1].connectedItem = item |
|
81 |
|
|
82 |
self.onSuccess.emit() |
|
83 |
except Exception as ex: |
|
84 |
from App import App |
|
85 |
from AppDocData import MessageType |
|
86 |
|
|
87 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
88 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
89 |
|
|
86 | 90 |
self.isTreated = True |
87 | 91 |
|
88 |
|
|
89 | 92 |
def undo(self): |
90 | 93 |
pass |
91 | 94 |
|
DTI_PID/DTI_PID/ItemTreeWidget.py | ||
---|---|---|
14 | 14 |
from PyQt4.QtGui import * |
15 | 15 |
except ImportError: |
16 | 16 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
17 |
|
|
17 | 18 |
from SymbolSvgItem import SymbolSvgItem |
18 | 19 |
from EngineeringTextItem import QEngineeringTextItem |
19 | 20 |
from EngineeringNoteItem import QEngineeringNoteItem |
... | ... | |
481 | 482 |
@date 2018.09.17 |
482 | 483 |
''' |
483 | 484 |
def InitLineNoItems(self): |
484 |
|
|
485 |
removeLineItem = [] |
|
486 |
for lineIndex in range(self.LineNoTreeItem.childCount()): |
|
487 |
## LineNoItem, TrimLine Item |
|
488 |
lineItem = self.LineNoTreeItem.child(lineIndex) |
|
489 |
|
|
490 |
removeRunItem = [] |
|
491 |
for runIndex in range(lineItem.childCount()): |
|
492 |
## RUN Item |
|
493 |
runItem = lineItem.child(runIndex) |
|
494 |
for symbolIndex in range(runItem.childCount()): |
|
495 |
symbolItem = runItem.child(0) |
|
496 |
symbol = symbolItem.data(0, self.TREE_DATA_ROLE) |
|
497 |
|
|
498 |
symbolItem.parent().removeChild(symbolItem) |
|
499 |
|
|
500 |
if AppDocData.instance().isEquipmentType(symbol.type): |
|
501 |
symbolsRootItem = self.findItems('EQUIPMENTS', Qt.MatchExactly|Qt.MatchRecursive, 0) |
|
502 |
symbolsRootItem = symbolsRootItem[0] |
|
503 |
symbolsRootItem.addChild(symbolItem) |
|
504 |
else: |
|
505 |
symbolsRootItem = self.findItems('SYMBOLS', Qt.MatchExactly|Qt.MatchRecursive, 0) |
|
506 |
symbolsRootItem = symbolsRootItem[0] |
|
507 |
symbolsRootItem.addChild(symbolItem) |
|
508 |
## 지울 Item 모음 |
|
509 |
removeRunItem.append(runItem) |
|
510 |
## Run Item들 삭제 |
|
511 |
for removeItem in removeRunItem: |
|
512 |
lineItem.removeChild(removeItem) |
|
513 |
## 지울 Trim Line 모음 |
|
514 |
if lineItem.text(0) == 'Trim Line': |
|
515 |
removeLineItem.append(lineItem) |
|
516 |
## Trim Line들 삭제 |
|
517 |
for removeItem in removeLineItem: |
|
518 |
self.LineNoTreeItem.removeChild(removeItem) |
|
485 |
try: |
|
486 |
removeLineItem = [] |
|
487 |
for lineIndex in range(self.LineNoTreeItem.childCount()): |
|
488 |
## LineNoItem, TrimLine Item |
|
489 |
lineItem = self.LineNoTreeItem.child(lineIndex) |
|
490 |
|
|
491 |
removeRunItem = [] |
|
492 |
for runIndex in range(lineItem.childCount()): |
|
493 |
## RUN Item |
|
494 |
runItem = lineItem.child(runIndex) |
|
495 |
for symbolIndex in range(runItem.childCount()): |
|
496 |
symbolItem = runItem.child(0) |
|
497 |
symbol = symbolItem.data(0, self.TREE_DATA_ROLE) |
|
498 |
|
|
499 |
symbolItem.parent().removeChild(symbolItem) |
|
500 |
|
|
501 |
if AppDocData.instance().isEquipmentType(symbol.type): |
|
502 |
self.EqpTreeItem.addChild(symbolItem) |
|
503 |
else: |
|
504 |
self.SymbolsTreeItem.addChild(symbolItem) |
|
505 |
|
|
506 |
## 지울 Item 모음 |
|
507 |
removeRunItem.append(runItem) |
|
508 |
## Run Item들 삭제 |
|
509 |
for removeItem in removeRunItem: |
|
510 |
lineItem.removeChild(removeItem) |
|
511 |
## 지울 Trim Line 모음 |
|
512 |
if lineItem.text(0) == 'Trim Line': |
|
513 |
removeLineItem.append(lineItem) |
|
514 |
## Trim Line들 삭제 |
|
515 |
for removeItem in removeLineItem: |
|
516 |
self.LineNoTreeItem.removeChild(removeItem) |
|
517 |
|
|
518 |
except Exception as ex: |
|
519 |
from App import App |
|
520 |
from AppDocData import MessageType |
|
521 |
|
|
522 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
523 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
519 | 524 |
|
520 | 525 |
''' |
521 | 526 |
@brief Find QTreeWidgetItem by SymbolSvgItem object |
DTI_PID/DTI_PID/LineNoTracer.py | ||
---|---|---|
325 | 325 |
tracer.execute(worker.displayMessage, worker.updateProgress) |
326 | 326 |
# up to here |
327 | 327 |
|
328 |
findSymbols = [symbol for symbol in worker.graphicsView.scene.items() if type(symbol) is SymbolSvgItem and symbol.hasInstrumentLabel == 1] |
|
329 |
for symbol in findSymbols: |
|
330 |
symbol.getConnectedLabel(worker) |
|
331 |
|
|
332 | 328 |
# connect attribut |
333 | 329 |
texts = [item for item in worker.graphicsView.scene.items() if issubclass(type(item), QEngineeringTextItem)] |
334 | 330 |
for symbol in symbols: |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
2050 | 2050 |
symbols = [item for item in self.graphicsView.scene.items() if issubclass(type(item), SymbolSvgItem) and len(item.attrs) > 0] |
2051 | 2051 |
for symbol in symbols: |
2052 | 2052 |
# 처음에는 attrs의 uid가 connectedItem에 String으로 들어가있기 때문에 |
2053 |
for index in range(len(symbol.attrs)):
|
|
2054 |
if type(symbol.attrs[index]) is not UserInputAttribute and type(symbol.attrs[index]) is not tuple:
|
|
2055 |
symbol.attrs[index] = self.graphicsView.findItemByUid(symbol.attrs[index])
|
|
2053 |
for key in symbol.attrs.keys():
|
|
2054 |
if type(symbol.attrs[key]) is not UserInputAttribute and type(symbol.attrs[key]) is not tuple:
|
|
2055 |
symbol.attrs[key] = self.graphicsView.findItemByUid(symbol.attrs[key])
|
|
2056 | 2056 |
|
2057 | 2057 |
# Update Scene |
2058 | 2058 |
self.graphicsView.scene.update(self.graphicsView.sceneRect()) |
... | ... | |
2170 | 2170 |
removeAttrList.append(attr) |
2171 | 2171 |
continue |
2172 | 2172 |
|
2173 |
attrInfo = docData.getSymbolAttributeByUID(attr.attribute)
|
|
2173 |
attrInfo = docData.getSymbolAttributeByUID(attr.UID)
|
|
2174 | 2174 |
if attrInfo is None: |
2175 | 2175 |
removeAttrList.append(attr) |
2176 | 2176 |
# 해당 attribute가 맞는지 확인 |
2177 | 2177 |
else: |
2178 |
attrType = attrInfo[2]
|
|
2178 |
attrType = attrInfo.AttributeType
|
|
2179 | 2179 |
_type = type(attr) |
2180 | 2180 |
if attrType == 'Symbol Item': |
2181 | 2181 |
if not issubclass(_type, SymbolSvgItem): |
... | ... | |
2191 | 2191 |
removeAttrList.append(attr) |
2192 | 2192 |
|
2193 | 2193 |
for attr in removeAttrList: |
2194 |
attrs.remove(attr)
|
|
2194 |
del attrs[attr]
|
|
2195 | 2195 |
|
2196 | 2196 |
# Line No Text Item의 경우 |
2197 | 2197 |
items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), QEngineeringLineNoTextItem)] |
... | ... | |
2206 | 2206 |
removeAttrList.append(attr) |
2207 | 2207 |
|
2208 | 2208 |
for attr in removeAttrList: |
2209 |
attrs.remove(attr)
|
|
2209 |
del attrs[attr]
|
|
2210 | 2210 |
|
2211 | 2211 |
except Exception as ex: |
2212 | 2212 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py | ||
---|---|---|
15 | 15 |
self._area = None |
16 | 16 |
self.connectors = [] |
17 | 17 |
self.attrs = {} # attributes |
18 |
self._associations = {} # associated items |
|
18 | 19 |
|
19 | 20 |
''' |
20 | 21 |
@brief Abstract method. Variable [color] is RGB hex code |
... | ... | |
90 | 91 |
@author humkyung |
91 | 92 |
@date 2018.11.07 |
92 | 93 |
""" |
93 |
pass |
|
94 |
pass |
|
95 |
|
|
96 |
def add_assoc_item(self, item): |
|
97 |
""" |
|
98 |
add given item to association |
|
99 |
""" |
|
100 |
|
|
101 |
from EngineeringTextItem import QEngineeringTextItem |
|
102 |
from SymbolSvgItem import SymbolSvgItem |
|
103 |
|
|
104 |
_type = None |
|
105 |
if type(item) is QEngineeringTextItem or issubclass(type(item), QEngineeringTextItem): |
|
106 |
_type = 'Text Item' |
|
107 |
elif type(item) is SymbolSvgItem or issubclass(type(item), SymbolSvgItem): |
|
108 |
_type = 'Symbol Item' |
|
109 |
|
|
110 |
if _type is not None: |
|
111 |
if not _type in self._associations: |
|
112 |
self._associations[_type] = [] |
|
113 |
|
|
114 |
self._associations[_type].append(item) |
DTI_PID/DTI_PID/Shapes/EngineeringEquipmentItem.py | ||
---|---|---|
30 | 30 |
appDocData = AppDocData.instance() |
31 | 31 |
QEngineeringEquipmentItem.EQUIP_COLUMN_LIST = appDocData.getColNames('EQUIPMENT_DATA_LIST') |
32 | 32 |
|
33 |
def texts(self): |
|
34 |
""" |
|
35 |
return text type of labels |
|
36 |
""" |
|
37 |
from EngineeringTextItem import QEngineeringTextItem |
|
38 |
|
|
39 |
return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1]) |
|
40 |
|
|
33 | 41 |
''' |
34 | 42 |
@brief connect attribute |
35 | 43 |
@author humkyung |
... | ... | |
38 | 46 |
def connectAttribute(self, attributes): |
39 | 47 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
40 | 48 |
|
41 |
self._texts.clear() |
|
42 |
|
|
43 |
""" |
|
44 |
rect = self.sceneBoundingRect() |
|
45 |
attrs = [attr for attr in attributes if type(attr) is QEngineeringTagNoTextItem] |
|
46 |
# check if text locates inside equipment |
|
47 |
for attr in attrs: |
|
48 |
if rect.contains(attr.center()): |
|
49 |
self.attrs.append(attr) |
|
50 |
attrs.remove(attr) |
|
51 |
break |
|
52 |
|
|
53 |
if not self.attrs: |
|
54 |
minDist = None |
|
55 |
selected = None |
|
56 |
# get nearest text from equipment |
|
57 |
for attr in attrs: |
|
58 |
dx = attr.center().x() - rect.center().x() |
|
59 |
dy = attr.center().y() - rect.center().y() |
|
60 |
dist = math.sqrt(dx*dx + dy*dy) |
|
61 |
if (minDist is None) or (dist < minDist): |
|
62 |
minDist = dist |
|
63 |
selected = attr |
|
64 |
|
|
65 |
if selected is not None: self.attrs.append(selected) |
|
66 |
""" |
|
49 |
self._associations.clear() |
|
67 | 50 |
|
68 | 51 |
try: |
69 | 52 |
rect = self.sceneBoundingRect() |
70 | 53 |
attrs = [attr for attr in attributes if type(attr) is QEngineeringTagNoTextItem] |
71 | 54 |
for attr in attrs: |
72 | 55 |
if rect.contains(attr.center()): |
73 |
self._texts.append(attr)
|
|
56 |
self.add_assoc_item(attr)
|
|
74 | 57 |
|
75 |
if not self._texts:
|
|
58 |
if not 'Text Item' in self._associations or not self._associations['Text Item']:
|
|
76 | 59 |
minDist = None |
77 | 60 |
selected = None |
78 | 61 |
# get nearest text from equipment |
... | ... | |
84 | 67 |
minDist = dist |
85 | 68 |
selected = attr |
86 | 69 |
|
87 |
if selected is not None: self._texts.append(selected) |
|
88 |
|
|
89 |
self._texts = sorted(self._texts, key=lambda attr: attr.loc[1]) # sort by y coordinate |
|
70 |
if selected is not None: self.add_assoc_item(selected) |
|
90 | 71 |
except Exception as ex: |
91 | 72 |
from App import App |
92 | 73 |
from AppDocData import MessageType |
... | ... | |
108 | 89 |
# 해당 Type의 attribute setting |
109 | 90 |
docData = AppDocData.instance() |
110 | 91 |
symbolAttrs = docData.getSymbolAttribute(self.type) |
92 |
|
|
93 |
_texts = self.texts() |
|
94 |
_symbols = self.symbols() |
|
111 | 95 |
for attr in symbolAttrs: |
112 | 96 |
if attr.AttributeType == 'Text Item': |
113 | 97 |
at = int(attr.AttrAt) |
114 |
if len(self._texts) > at:
|
|
115 |
item = self._texts[at]
|
|
98 |
if len(_texts) > at: |
|
99 |
item = _texts[at] |
|
116 | 100 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
117 | 101 |
else: |
118 | 102 |
_attrs[attr] = '' |
119 | 103 |
elif attr.AttributeType == 'Symbol Item': |
120 | 104 |
at = int(attr.AttrAt) |
121 |
if len(self._symbols) > at:
|
|
122 |
item = self._symbols[at]
|
|
105 |
if len(_symbols) > at: |
|
106 |
item = _symbols[at] |
|
123 | 107 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
124 | 108 |
else: |
125 | 109 |
_attrs[attr] = '' |
... | ... | |
156 | 140 |
@date 2018.05.03 |
157 | 141 |
''' |
158 | 142 |
def toXmlAsAttribute(self, parentNode): |
159 |
for attr in self._texts:
|
|
143 |
for attr in self.texts():
|
|
160 | 144 |
parentNode.append(attr.toXml(self, None)) |
161 | 145 |
|
162 | 146 |
def toSql(self): |
DTI_PID/DTI_PID/Shapes/EngineeringInstrumentItem.py | ||
---|---|---|
21 | 21 |
This is Engineering Instrument Item class |
22 | 22 |
""" |
23 | 23 |
clicked = pyqtSignal(QGraphicsSvgItem) |
24 |
#removed = pyqtSignal(QGraphicsItem) |
|
25 |
INST_COLUMN_LIST = None #['UID', 'ITEM_NO', 'SERVICE', 'FLOW_RATE', 'PRESSURE', 'TEMPERATURE', 'TPYE', 'RANGE', 'NOR_LEVEL_MM', 'NOR_LEVEL_PERCENT', 'DEL_PRESS', 'SHUT_OFF', 'LOCATION', 'PNID_NO', 'REV'] |
|
24 |
INST_COLUMN_LIST = None |
|
26 | 25 |
|
27 | 26 |
''' |
28 | 27 |
''' |
... | ... | |
46 | 45 |
""" |
47 | 46 |
from EngineeringTextItem import QEngineeringTextItem |
48 | 47 |
|
49 |
if self.labels(): |
|
50 |
return sorted([x for x in self.labels() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1]) |
|
51 |
|
|
52 |
return [] |
|
48 |
return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1]) |
|
53 | 49 |
|
54 | 50 |
''' |
55 | 51 |
@brief getter of measured variable code |
... | ... | |
129 | 125 |
@date 2018.05.06 |
130 | 126 |
''' |
131 | 127 |
def connectAttribute(self, attributes): |
132 |
self._texts.clear() |
|
133 |
self._symbols.clear() |
|
128 |
self._associations.clear() |
|
134 | 129 |
|
135 | 130 |
try: |
136 | 131 |
rect = self.sceneBoundingRect() |
... | ... | |
138 | 133 |
if rect.contains(attr.center()): |
139 | 134 |
if issubclass(type(attr), QEngineeringTextItem): |
140 | 135 |
attr.owner = self # set owner of text |
141 |
self._labels.append(attr)
|
|
136 |
self.add_assoc_item(attr)
|
|
142 | 137 |
elif issubclass(type(attr), SymbolSvgItem): |
143 | 138 |
attr._owner = self.uid # set owner of symbol |
144 |
self._labels.append(attr) |
|
145 |
|
|
146 |
#self._texts = sorted(self._texts, key=lambda attr: attr.loc[1]) # sort by y coordinate |
|
139 |
self.add_assoc_item(attr) |
|
147 | 140 |
except Exception as ex: |
148 | 141 |
from App import App |
149 | 142 |
from AppDocData import MessageType |
DTI_PID/DTI_PID/Shapes/EngineeringSpecBreakItem.py | ||
---|---|---|
22 | 22 |
def __init__(self, path, uid=None): |
23 | 23 |
SymbolSvgItem.__init__(self, path, uid) |
24 | 24 |
|
25 |
|
|
26 |
|
|
27 | 25 |
|
28 | 26 |
''' |
29 | 27 |
@brief get attribute |
DTI_PID/DTI_PID/Shapes/QEngineeringOPCItem.py | ||
---|---|---|
65 | 65 |
from AppDocData import AppDocData, MessageType |
66 | 66 |
|
67 | 67 |
self.attrs.clear() |
68 |
self._texts.clear()
|
|
68 |
self._associations.clear()
|
|
69 | 69 |
|
70 | 70 |
try: |
71 | 71 |
rect = self.sceneBoundingRect() |
72 | 72 |
for attr in attributes: |
73 | 73 |
if rect.contains(attr.center()): |
74 |
self._texts.append(attr)
|
|
74 |
self.add_assoc_item(attr)
|
|
75 | 75 |
|
76 |
if 0 == self.angle: |
|
77 |
sorted(self._texts, key=lambda attr: attr.loc[0]) # sort by x coordinate |
|
78 |
elif 3.14 == self.angle: |
|
79 |
sorted(self._texts, key=lambda attr: attr.loc[0], reverse=True) # sort by x coordinate by descending |
|
80 |
elif 1.57 == self.angle: |
|
81 |
sorted(self._texts, key=lambda attr: attr.loc[1], reverse=True) # sort by y coordinate |
|
82 |
elif 4.71 == self.angle: |
|
83 |
sorted(self._texts, key=lambda attr: attr.loc[1]) # sort by y coordinate |
|
76 |
if 'Text Item' in self._associations and self._associations['Text Item']: |
|
77 |
if 0 == self.angle: |
|
78 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[0]) # sort by x coordinate |
|
79 |
elif 3.14 == self.angle: |
|
80 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[0], reverse=True) # sort by x coordinate by descending |
|
81 |
elif 1.57 == self.angle: |
|
82 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[1], reverse=True) # sort by y coordinate |
|
83 |
elif 4.71 == self.angle: |
|
84 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[1]) # sort by y coordinate |
|
84 | 85 |
except Exception as ex: |
85 | 86 |
from App import App |
86 | 87 |
|
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
50 | 50 |
# attributeType uid |
51 | 51 |
self.attribute = '' |
52 | 52 |
|
53 |
self._labels = [] |
|
54 |
self._texts = [] # contains text items |
|
55 |
self._symbols = [] # contains symbol items |
|
56 |
|
|
57 | 53 |
self.setAcceptHoverEvents(True) |
58 | 54 |
self.setAcceptedMouseButtons(Qt.LeftButton) |
59 | 55 |
self.setAcceptTouchEvents(True) |
... | ... | |
102 | 98 |
self._color = self.DEFAULT_COLOR |
103 | 99 |
self.setColor(self._color) |
104 | 100 |
|
105 |
def labels(self):
|
|
101 |
def associations(self):
|
|
106 | 102 |
""" |
107 |
return label instance
|
|
103 |
return associated instance
|
|
108 | 104 |
""" |
109 | 105 |
import uuid |
110 | 106 |
|
111 | 107 |
res = [] |
112 |
for label in self._labels: |
|
113 |
# find owner with uid |
|
114 |
if label and type(label) is uuid.UUID: |
|
115 |
matches = [x for x in self.scene().items() if hasattr(x, 'uid') and x.uid == label] |
|
116 |
if matches: res.append(matches[0]) |
|
117 |
# up to here |
|
118 |
elif label: |
|
119 |
res.append(label) |
|
108 |
for key in self._associations.keys(): |
|
109 |
for assoc in self._associations[key]: |
|
110 |
# find owner with uid |
|
111 |
if assoc and type(assoc) is uuid.UUID: |
|
112 |
matches = [x for x in self.scene().items() if hasattr(x, 'uid') and x.uid == assoc] |
|
113 |
if matches: res.append(matches[0]) |
|
114 |
# up to here |
|
115 |
elif assoc: |
|
116 |
res.append(assoc) |
|
120 | 117 |
|
121 | 118 |
return res |
122 | 119 |
|
123 | 120 |
def texts(self): |
124 | 121 |
""" |
125 |
return text type of labels
|
|
122 |
return text type of associations
|
|
126 | 123 |
""" |
127 | 124 |
from EngineeringTextItem import QEngineeringTextItem |
128 | 125 |
|
129 |
return [x for x in self.labels() if issubclass(type(x), QEngineeringTextItem)]
|
|
126 |
return [x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)]
|
|
130 | 127 |
|
131 | 128 |
def symbols(self): |
132 | 129 |
""" |
133 |
return symbol type of labels
|
|
130 |
return symbol type of associations
|
|
134 | 131 |
""" |
135 |
return [x for x in self.labels() if issubclass(type(x), SymbolSvgItem)]
|
|
132 |
return [x for x in self.associations() if issubclass(type(x), SymbolSvgItem)]
|
|
136 | 133 |
|
137 | 134 |
def toSql(self): |
138 | 135 |
""" |
... | ... | |
465 | 462 |
def removeSelfAttr(self, attributeName): |
466 | 463 |
for attr in self.attrs: |
467 | 464 |
if attr.attribute == attributeName: |
468 |
self.attrs.remove(attr)
|
|
465 |
del self.attrs[attr]
|
|
469 | 466 |
|
470 | 467 |
''' |
471 | 468 |
@brief Find TextItem contain Point |
... | ... | |
539 | 536 |
def connectAttribute(self, attributes): |
540 | 537 |
import math |
541 | 538 |
from QEngineeringSizeTextItem import QEngineeringSizeTextItem |
539 |
from EngineeringInstrumentItem import QEngineeringInstrumentItem |
|
542 | 540 |
|
543 | 541 |
self.attrs.clear() |
544 |
self._labels.clear()
|
|
542 |
self._associations.clear()
|
|
545 | 543 |
|
546 | 544 |
try: |
547 | 545 |
dist = max(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) |
... | ... | |
557 | 555 |
if (length < dist*2) and (minDist is None or length < minDist): |
558 | 556 |
minDist = length |
559 | 557 |
selected = attr |
558 |
elif type(attr) is QEngineeringInstrumentItem: |
|
559 |
isConnected = False |
|
560 |
for connector in attr.connectors: |
|
561 |
if connector.connectedItem is not None: |
|
562 |
isConnected = True |
|
563 |
break |
|
564 |
|
|
565 |
if isConnected == False: |
|
566 |
dx = attr.origin[0] - self.origin[0] |
|
567 |
dy = attr.origin[1] - self.origin[1] |
|
568 |
if math.sqrt(dx*dx + dy*dy) < 200: |
|
569 |
self.add_assoc_item(symbol) |
|
560 | 570 |
|
561 | 571 |
if selected is not None: |
562 |
self._labels.append(selected)
|
|
563 |
#self._texts.append(selected) |
|
572 |
self.add_assoc_item(selected)
|
|
573 |
|
|
564 | 574 |
except Exception as ex: |
565 | 575 |
from App import App |
566 | 576 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
567 | 577 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
568 | 578 |
|
569 | 579 |
''' |
570 |
@Auther Yecheol |
|
571 |
@Date 2018.07.06 |
|
572 |
@History add Get not connected Attribute Item |
|
573 |
humkyung 2018.07.23 fixed the code |
|
574 |
''' |
|
575 |
def getConnectedLabel(self, worker): |
|
576 |
import math |
|
577 |
from EngineeringInstrumentItem import QEngineeringInstrumentItem |
|
578 |
|
|
579 |
findSymbols = [symbol for symbol in worker.graphicsView.scene.items() if type(symbol) is QEngineeringInstrumentItem] |
|
580 |
|
|
581 |
for symbol in findSymbols: |
|
582 |
isConnected = False |
|
583 |
for connector in symbol.connectors: |
|
584 |
if connector.connectedItem is not None: |
|
585 |
isConnected = True |
|
586 |
break |
|
587 |
|
|
588 |
if isConnected == False: |
|
589 |
dx = symbol.origin[0] - self.origin[0] |
|
590 |
dy = symbol.origin[1] - self.origin[1] |
|
591 |
if math.sqrt(dx*dx + dy*dy) < 200: |
|
592 |
self.attrs.append(symbol) |
|
593 |
|
|
594 |
''' |
|
595 | 580 |
@brief get attribute |
596 | 581 |
@author humkyung |
597 | 582 |
@date 2018.06.14 |
... | ... | |
606 | 591 |
# 해당 Type의 attribute setting |
607 | 592 |
docData = AppDocData.instance() |
608 | 593 |
symbolAttrs = docData.getSymbolAttribute(self.type) |
594 |
|
|
595 |
_texts = self.texts() |
|
596 |
_symbols = self.symbols() |
|
609 | 597 |
for attr in symbolAttrs: |
610 | 598 |
if attr.AttributeType == 'Text Item': |
611 | 599 |
at = int(attr.AttrAt) |
612 |
if len(self._texts) > at:
|
|
613 |
item = self._texts[at]
|
|
600 |
if len(_texts) > at: |
|
601 |
item = _texts[at] |
|
614 | 602 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
615 | 603 |
else: |
616 | 604 |
_attrs[attr] = '' |
617 | 605 |
elif attr.AttributeType == 'Symbol Item': |
618 | 606 |
at = int(attr.AttrAt) |
619 |
if len(self._symbols) > at:
|
|
620 |
item = self._symbols[at]
|
|
607 |
if len(_symbols) > at: |
|
608 |
item = _symbols[at] |
|
621 | 609 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
622 | 610 |
else: |
623 | 611 |
_attrs[attr] = '' |
... | ... | |
652 | 640 |
''' |
653 | 641 |
def toXml(self): |
654 | 642 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
643 |
from EngineeringTextItem import QEngineeringTextItem |
|
655 | 644 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
656 | 645 |
from SymbolAttr import SymbolAttr |
657 | 646 |
|
... | ... | |
665 | 654 |
nameNode.text = self.name |
666 | 655 |
node.append(nameNode) |
667 | 656 |
|
668 |
attributeValueNode = Element('LABELS') |
|
669 |
for label in self.labels: |
|
670 |
labelNode = Element('LABEL') |
|
671 |
labelNode.text = str(label.uid) |
|
672 |
attributeValueNode.append(labelNode) |
|
657 |
attributeValueNode = Element('ASSOCIATIONS') |
|
658 |
for assoc in self.associations(): |
|
659 |
assoc_node = Element('ASSOCIATION') |
|
660 |
assoc_node.attrib['TYPE'] = 'Text Item' if issubclass(type(assoc), QEngineeringTextItem) else 'Symbol Item' |
|
661 |
assoc_node.text = str(assoc.uid) |
|
662 |
attributeValueNode.append(assoc_node) |
|
673 | 663 |
node.append(attributeValueNode) |
674 | 664 |
|
675 | 665 |
typeNode = Element('TYPE') |
... | ... | |
843 | 833 |
|
844 | 834 |
iterIndex += 1 |
845 | 835 |
|
846 |
# get labels
|
|
847 |
attributeValue = node.find('LABELS')
|
|
836 |
# get associations
|
|
837 |
attributeValue = node.find('ASSOCIATIONS')
|
|
848 | 838 |
if attributeValue is not None: |
849 |
for label in attributeValue.iter('LABEL'): |
|
850 |
item[0]._labels.append(uuid.UUID(label.text)) |
|
839 |
for assoc in attributeValue.iter('ASSOCIATION'): |
|
840 |
_type = assoc.attrib['TYPE'] |
|
841 |
if not _type in item[0]._associations: |
|
842 |
item[0]._associations[_type] = [] |
|
843 |
item[0]._associations[_type].append(uuid.UUID(assoc.text)) |
|
851 | 844 |
# up to here |
852 | 845 |
|
853 | 846 |
attributes = node.find('SYMBOLATTRIBUTES') |
내보내기 Unified diff