hytos / DTI_PID / DTI_PID / Shapes / EngineeringNozzleItem.py @ ed948580
이력 | 보기 | 이력해설 | 다운로드 (2.7 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 |
|
14 |
class QEngineeringNozzleItem(SymbolSvgItem): |
15 |
ZVALUE = 20
|
16 |
clicked = pyqtSignal(QGraphicsSvgItem) |
17 |
|
18 |
'''
|
19 |
'''
|
20 |
def __init__(self, path, uid=None): |
21 |
SymbolSvgItem.__init__(self, path, uid)
|
22 |
|
23 |
self._props = [['Name', None], ['Size', None]] |
24 |
self.setZValue(QEngineeringNozzleItem.ZVALUE)
|
25 |
|
26 |
'''
|
27 |
@brief getter of property
|
28 |
@author humkyung
|
29 |
@date 2018.07.29
|
30 |
'''
|
31 |
@property
|
32 |
def props(self): |
33 |
return self._props |
34 |
|
35 |
'''
|
36 |
@brief connect attribute
|
37 |
@author humkyung
|
38 |
@date 2018.07.19
|
39 |
'''
|
40 |
def connectAttribute(self, attributes): |
41 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
42 |
|
43 |
self.attrs.clear()
|
44 |
|
45 |
super(QEngineeringNozzleItem, self).connectAttribute(attributes) |
46 |
|
47 |
rect = self.sceneBoundingRect()
|
48 |
attrs = [attr for attr in attributes if type(attr) is QEngineeringTagNoTextItem] |
49 |
# check if text locates inside equipment
|
50 |
for attr in attrs: |
51 |
if rect.contains(attr.center()):
|
52 |
self.attrs.append(attr)
|
53 |
attrs.remove(attr) |
54 |
break
|
55 |
|
56 |
if not self.attrs: |
57 |
minDist = None
|
58 |
selected = None
|
59 |
# get nearest text from nozzle
|
60 |
for attr in attrs: |
61 |
dx = attr.center().x() - rect.center().x() |
62 |
dy = attr.center().y() - rect.center().y() |
63 |
dist = math.sqrt(dx*dx + dy*dy) |
64 |
if (minDist is None) or (dist < minDist): |
65 |
minDist = dist |
66 |
selected = attr |
67 |
|
68 |
if selected is not None: self.attrs.append(selected) |
69 |
|
70 |
'''
|
71 |
@brief generate xml code for nozzle
|
72 |
@author humkyung
|
73 |
@date 2018.07.19
|
74 |
'''
|
75 |
def toXml(self): |
76 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
77 |
|
78 |
try:
|
79 |
node = SymbolSvgItem.toXml(self)
|
80 |
self.toXmlAsAttribute(node)
|
81 |
except Exception as ex: |
82 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
83 |
|
84 |
return node
|
85 |
|
86 |
'''
|
87 |
@brief generate xml code for attribute
|
88 |
@author humkyung
|
89 |
@date 2018.07.19
|
90 |
'''
|
91 |
def toXmlAsAttribute(self, parentNode): |
92 |
for attr in self.attrs: |
93 |
parentNode.append(attr.toXml(self, None)) |