hytos / DTI_PID / DTI_PID / Shapes / EngineeringEquipmentItem.py @ 42176339
이력 | 보기 | 이력해설 | 다운로드 (7.31 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 |
class QEngineeringEquipmentItem(SymbolSvgItem): |
17 |
clicked = pyqtSignal(QGraphicsSvgItem) |
18 |
ZVALUE = 10
|
19 |
EQUIP_COLUMN_LIST = None #['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'] |
20 |
|
21 |
'''
|
22 |
'''
|
23 |
def __init__(self, path, uid=None): |
24 |
SymbolSvgItem.__init__(self, path, uid)
|
25 |
self.setZValue(QEngineeringEquipmentItem.ZVALUE)
|
26 |
|
27 |
if QEngineeringEquipmentItem.EQUIP_COLUMN_LIST is None: |
28 |
from AppDocData import AppDocData |
29 |
|
30 |
appDocData = AppDocData.instance() |
31 |
QEngineeringEquipmentItem.EQUIP_COLUMN_LIST = appDocData.getColNames('EQUIPMENT_DATA_LIST')
|
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 |
|
41 |
'''
|
42 |
@brief connect attribute
|
43 |
@author humkyung
|
44 |
@date 2018.05.03
|
45 |
'''
|
46 |
def connectAttribute(self, attributes): |
47 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
48 |
|
49 |
self._associations.clear()
|
50 |
|
51 |
try:
|
52 |
rect = self.sceneBoundingRect()
|
53 |
attrs = [attr for attr in attributes if type(attr) is QEngineeringTagNoTextItem] |
54 |
for attr in attrs: |
55 |
if rect.contains(attr.center()):
|
56 |
self.add_assoc_item(attr)
|
57 |
|
58 |
if not 'Text Item' in self._associations or not self._associations['Text Item']: |
59 |
minDist = None
|
60 |
selected = None
|
61 |
# get nearest text from equipment
|
62 |
for attr in attrs: |
63 |
dx = attr.center().x() - rect.center().x() |
64 |
dy = attr.center().y() - rect.center().y() |
65 |
dist = math.sqrt(dx*dx + dy*dy) |
66 |
if (minDist is None) or (dist < minDist): |
67 |
minDist = dist |
68 |
selected = attr |
69 |
|
70 |
if selected is not None: self.add_assoc_item(selected) |
71 |
except Exception as ex: |
72 |
from App import App |
73 |
from AppDocData import MessageType |
74 |
|
75 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
76 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
77 |
|
78 |
'''
|
79 |
@brief get attributes
|
80 |
@author humkyung
|
81 |
@date 2018.06.14
|
82 |
'''
|
83 |
def getAttributes(self): |
84 |
_attrs = {} |
85 |
try:
|
86 |
from AppDocData import AppDocData |
87 |
from EngineeringTextItem import QEngineeringTextItem |
88 |
|
89 |
# 해당 Type의 attribute setting
|
90 |
docData = AppDocData.instance() |
91 |
symbolAttrs = docData.getSymbolAttribute(self.type)
|
92 |
|
93 |
_texts = self.texts()
|
94 |
_symbols = self.symbols()
|
95 |
for attr in symbolAttrs: |
96 |
if attr.AttributeType == 'Text Item': |
97 |
at = int(attr.AttrAt)
|
98 |
if len(_texts) > at: |
99 |
item = _texts[at] |
100 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
101 |
else:
|
102 |
_attrs[attr] = ''
|
103 |
elif attr.AttributeType == 'Symbol Item': |
104 |
at = int(attr.AttrAt)
|
105 |
if len(_symbols) > at: |
106 |
item = _symbols[at] |
107 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
108 |
else:
|
109 |
_attrs[attr] = ''
|
110 |
else:
|
111 |
_attrs[attr] = ''#self.attrs[attr[1]] if attr[1] in self.attrs.keys() else '' |
112 |
except Exception as ex: |
113 |
from App import App |
114 |
from AppDocData import MessageType |
115 |
|
116 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
117 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
118 |
|
119 |
return _attrs
|
120 |
|
121 |
'''
|
122 |
@brief generate xml code for equipment
|
123 |
@author humkyung
|
124 |
@date 2018.05.09
|
125 |
'''
|
126 |
def toXml(self): |
127 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
128 |
|
129 |
try:
|
130 |
node = SymbolSvgItem.toXml(self)
|
131 |
self.toXmlAsAttribute(node)
|
132 |
except Exception as ex: |
133 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
134 |
|
135 |
return node
|
136 |
|
137 |
'''
|
138 |
@brief generate xml code for attribute
|
139 |
@author humkyung
|
140 |
@date 2018.05.03
|
141 |
'''
|
142 |
def toXmlAsAttribute(self, parentNode): |
143 |
for attr in self.texts(): |
144 |
parentNode.append(attr.toXml(self, None)) |
145 |
|
146 |
def toSql(self): |
147 |
"""
|
148 |
convert equipment data to sql query
|
149 |
"""
|
150 |
from AppDocData import AppDocData |
151 |
|
152 |
appDocData = AppDocData.instance() |
153 |
|
154 |
cols = ['UID', 'PNID_NO'] |
155 |
values = ['?','?'] |
156 |
param = [str(self.uid), appDocData.activeDrawing.name] |
157 |
_attrs = self.getAttributes()
|
158 |
for key in _attrs.keys(): |
159 |
cols.append(key.Attribute) |
160 |
values.append('?')
|
161 |
param.append(_attrs[key]) |
162 |
|
163 |
sql = 'insert or replace into EQUIPMENT_DATA_LIST({}) values({})'.format(','.join(cols), ','.join(values)) |
164 |
return (sql, tuple(param)) |
165 |
|
166 |
'''
|
167 |
@brief return equip Data List
|
168 |
@author kyouho
|
169 |
@date 2018.08.14
|
170 |
'''
|
171 |
def getEquipmentDataList(self): |
172 |
dataList = [] |
173 |
try:
|
174 |
from AppDocData import AppDocData |
175 |
|
176 |
docData = AppDocData.instance() |
177 |
attrs = self.attrs
|
178 |
|
179 |
for index in range(len(QEngineeringEquipmentItem.EQUIP_COLUMN_LIST)): |
180 |
dataList.append('')
|
181 |
|
182 |
dataList[0] = str(self.uid) |
183 |
dataList[14] = docData.imgName
|
184 |
|
185 |
for attr in attrs: |
186 |
attrInfo = docData.getSymbolAttributeByUID(attr.attribute) |
187 |
attrName = attrInfo[0]
|
188 |
if QEngineeringEquipmentItem.EQUIP_COLUMN_LIST.count(attrName):
|
189 |
colIndex = QEngineeringEquipmentItem.EQUIP_COLUMN_LIST.index(attrName) |
190 |
|
191 |
if type(attr) is UserInputAttribute: |
192 |
dataList[colIndex] = attr.text if attr.text is not None else '' |
193 |
elif type(attr) is QEngineeringTextItem: |
194 |
dataList[colIndex] = attr.text() |
195 |
else:
|
196 |
dataList[colIndex] = attr.uid |
197 |
|
198 |
except Exception as ex: |
199 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
200 |
|
201 |
return dataList
|