hytos / DTI_PID / DTI_PID / Shapes / QEngineeringEquipmentItem.py @ 94092f45
이력 | 보기 | 이력해설 | 다운로드 (4.58 KB)
1 |
# coding: utf-8
|
---|---|
2 |
|
3 |
import sys |
4 |
import os |
5 |
import math |
6 |
from PyQt5.QtGui import * |
7 |
from PyQt5.QtCore import * |
8 |
from PyQt5.QtSvg import * |
9 |
from PyQt5.QtWidgets import (QApplication, QGraphicsItem) |
10 |
|
11 |
from SymbolSvgItem import SymbolSvgItem |
12 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
13 |
from EngineeringTextItem import QEngineeringTextItem |
14 |
from UserInputAttribute import UserInputAttribute |
15 |
|
16 |
equipColumnList = ['UID', 'ITEM_NO', 'SERVICE', 'NO_REQ', 'FLUID', 'DESC_OF_PART', 'OPERATION_CONDITION_TEMP', 'OPERATION_CONDITION_PRESS', 'DESIGN_CONDITION_TEMP', 'DESIGN_CONDITION_PRESS', 'MATERIAL', 'WEIGHT', 'POWER', 'INSULATION', 'PNID_NO', 'REV'] |
17 |
|
18 |
class QEngineeringEquipmentItem(SymbolSvgItem): |
19 |
clicked = pyqtSignal(QGraphicsSvgItem) |
20 |
ZVALUE = 10
|
21 |
|
22 |
'''
|
23 |
'''
|
24 |
def __init__(self, path, uid=None): |
25 |
SymbolSvgItem.__init__(self, path, uid)
|
26 |
self.setZValue(QEngineeringEquipmentItem.ZVALUE)
|
27 |
|
28 |
'''
|
29 |
@brief connect attribute
|
30 |
@author humkyung
|
31 |
@date 2018.05.03
|
32 |
'''
|
33 |
def connectAttribute(self, attributes): |
34 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
35 |
|
36 |
self.attrs.clear()
|
37 |
|
38 |
rect = self.sceneBoundingRect()
|
39 |
attrs = [attr for attr in attributes if type(attr) is QEngineeringTagNoTextItem] |
40 |
# check if text locates inside equipment
|
41 |
for attr in attrs: |
42 |
if rect.contains(attr.center()):
|
43 |
self.attrs.append(attr)
|
44 |
attrs.remove(attr) |
45 |
break
|
46 |
|
47 |
if not self.attrs: |
48 |
minDist = None
|
49 |
selected = None
|
50 |
# get nearest text from equipment
|
51 |
for attr in attrs: |
52 |
dx = attr.center().x() - rect.center().x() |
53 |
dy = attr.center().y() - rect.center().y() |
54 |
dist = math.sqrt(dx*dx + dy*dy) |
55 |
if (minDist is None) or (dist < minDist): |
56 |
minDist = dist |
57 |
selected = attr |
58 |
|
59 |
if selected is not None: self.attrs.append(selected) |
60 |
|
61 |
'''
|
62 |
@brief generate xml code for equipment
|
63 |
@author humkyung
|
64 |
@date 2018.05.09
|
65 |
'''
|
66 |
def toXml(self): |
67 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
68 |
|
69 |
try:
|
70 |
node = SymbolSvgItem.toXml(self)
|
71 |
self.toXmlAsAttribute(node)
|
72 |
except Exception as ex: |
73 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
74 |
|
75 |
return node
|
76 |
|
77 |
'''
|
78 |
@brief generate xml code for attribute
|
79 |
@author humkyung
|
80 |
@date 2018.05.03
|
81 |
'''
|
82 |
def toXmlAsAttribute(self, parentNode): |
83 |
for attr in self.attrs: |
84 |
parentNode.append(attr.toXml(self, None)) |
85 |
|
86 |
'''
|
87 |
@brief save Line Data
|
88 |
@author kyouho
|
89 |
@date 2018.08.14
|
90 |
'''
|
91 |
def saveEquipData(self): |
92 |
try:
|
93 |
from AppDocData import AppDocData |
94 |
|
95 |
docData = AppDocData.instance() |
96 |
docData.setEquipmentDataList([self.getEquipmentDataList()])
|
97 |
except Exception as ex: |
98 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
99 |
return str(self.uid) |
100 |
|
101 |
'''
|
102 |
@brief return equip Data List
|
103 |
@author kyouho
|
104 |
@date 2018.08.14
|
105 |
'''
|
106 |
def getEquipmentDataList(self): |
107 |
dataList = [] |
108 |
try:
|
109 |
from AppDocData import AppDocData |
110 |
|
111 |
global equipColumnList
|
112 |
|
113 |
docData = AppDocData.instance() |
114 |
attrs = self.attrs
|
115 |
|
116 |
for index in range(len(equipColumnList)): |
117 |
dataList.append('')
|
118 |
|
119 |
dataList[0] = str(self.uid) |
120 |
dataList[14] = docData.imgName
|
121 |
|
122 |
for attr in attrs: |
123 |
attrInfo = docData.getSymbolAttributeByUID(attr.attribute) |
124 |
attrName = attrInfo[0]
|
125 |
if equipColumnList.count(attrName):
|
126 |
colIndex = equipColumnList.index(attrName) |
127 |
|
128 |
if type(attr) is UserInputAttribute: |
129 |
dataList[colIndex] = attr.text if attr.text is not None else '' |
130 |
elif type(attr) is QEngineeringTextItem: |
131 |
dataList[colIndex] = attr.text() |
132 |
else:
|
133 |
dataList[colIndex] = attr.uid |
134 |
|
135 |
except Exception as ex: |
136 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
137 |
|
138 |
return dataList
|