hytos / DTI_PID / DTI_PID / Shapes / QEngineeringOPCItem.py @ 1f2d866f
이력 | 보기 | 이력해설 | 다운로드 (4.97 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This engineering opc item module """
|
3 |
|
4 |
import sys |
5 |
import os |
6 |
import math |
7 |
from PyQt5.QtGui import * |
8 |
from PyQt5.QtCore import * |
9 |
from PyQt5.QtSvg import * |
10 |
from PyQt5.QtWidgets import (QApplication, QGraphicsItem) |
11 |
|
12 |
from SymbolSvgItem import SymbolSvgItem |
13 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
14 |
|
15 |
class QEngineeringOPCItem(SymbolSvgItem): |
16 |
""" This is engineering opc item class """
|
17 |
|
18 |
clicked = pyqtSignal(QGraphicsSvgItem) |
19 |
|
20 |
def __init__(self, path, uid=None, flip=0): |
21 |
from SymbolAttr import SymbolProp |
22 |
|
23 |
SymbolSvgItem.__init__(self, path, uid, flip=flip)
|
24 |
|
25 |
self._properties = \
|
26 |
{\ |
27 |
SymbolProp(None, 'Logical', 'String', Expression=None):'Process', |
28 |
SymbolProp(None, 'From', 'Text Item', Expression='self.From'):None, |
29 |
SymbolProp(None, 'To', 'Text Item', Expression='self.To'):None |
30 |
} |
31 |
|
32 |
'''
|
33 |
@brief getter of description
|
34 |
@author humkyung
|
35 |
@date 2018.05.08
|
36 |
'''
|
37 |
@property
|
38 |
def description(self): |
39 |
return self._description |
40 |
|
41 |
'''
|
42 |
@brief setter of description
|
43 |
@author humkyung
|
44 |
@date 2018.05.08
|
45 |
'''
|
46 |
@description.setter
|
47 |
def description(self, value): |
48 |
self._description = value
|
49 |
|
50 |
@property
|
51 |
def From(self): |
52 |
""" return From value """
|
53 |
return '' |
54 |
|
55 |
@property
|
56 |
def To(self): |
57 |
""" return To value """
|
58 |
return '' |
59 |
|
60 |
def includes(self, item): |
61 |
topLeft = [item.loc[0], item.loc[1]] |
62 |
bottomRight = [item.loc[0] + item.size[0], item.loc[1] + item.size[1]] |
63 |
if self.contains(topLeft) and self.contains(bottomRight): |
64 |
return True |
65 |
else:
|
66 |
return False |
67 |
|
68 |
def contains(self, pt): |
69 |
minX = self.loc[0] |
70 |
minY = self.loc[1] |
71 |
maxX = minX + self.size[0] |
72 |
maxY = minY + self.size[1] |
73 |
|
74 |
if pt[0] < minX: return False |
75 |
if pt[0] > maxX: return False |
76 |
if pt[1] < maxY: return False |
77 |
if pt[1] > minY: return False |
78 |
|
79 |
return True |
80 |
|
81 |
'''
|
82 |
@brief connect attribute
|
83 |
@author humkyung
|
84 |
@date 2018.05.02
|
85 |
'''
|
86 |
def connectAttribute(self, attributes, clear=True): |
87 |
from AppDocData import AppDocData, MessageType |
88 |
from EngineeringLineItem import QEngineeringLineItem |
89 |
|
90 |
try:
|
91 |
if clear:
|
92 |
self.clear_attr_and_assoc_item()
|
93 |
|
94 |
# return, opc attribute check manually
|
95 |
'''
|
96 |
|
97 |
app_doc_data = AppDocData.instance()
|
98 |
|
99 |
matches = [connector.connectedItem for connector in self.connectors if connector is not None and type(connector.connectedItem) is QEngineeringLineItem]
|
100 |
if matches:
|
101 |
if matches[0].connectors[0].connectedItem is self: # FROM
|
102 |
configs = app_doc_data.getConfigs('OPC Tag Rule', 'From Prefix')
|
103 |
elif matches[0].connectors[1].connectedItem is self: # TO
|
104 |
configs = app_doc_data.getConfigs('OPC Tag Rule', 'To Prefix')
|
105 |
|
106 |
self.set_property('Logical', 'Process' if (matches[0].lineType == 'Primary' or matches[0].lineType == 'Secondary') else 'Instrument') # set OPC type
|
107 |
|
108 |
rect = self.sceneBoundingRect()
|
109 |
for attr in attributes:
|
110 |
if rect.contains(attr.center()):
|
111 |
if self.add_assoc_item(attr):
|
112 |
attr.owner = self
|
113 |
|
114 |
self.associations() # to binding object from scene
|
115 |
if 'Text Item' in self._associations and self._associations['Text Item']:
|
116 |
if 0 == self.angle:
|
117 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[0]) # sort by x coordinate
|
118 |
elif 3.14 == self.angle:
|
119 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[0], reverse=True) # sort by x coordinate by descending
|
120 |
elif 1.57 == self.angle:
|
121 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[1], reverse=True) # sort by y coordinate
|
122 |
elif 4.71 == self.angle:
|
123 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[1]) # sort by y coordinate
|
124 |
'''
|
125 |
except Exception as ex: |
126 |
from App import App |
127 |
from AppDocData import MessageType |
128 |
|
129 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
130 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
131 |
|
132 |
'''
|
133 |
@brief generate xml code for attribute
|
134 |
@author humkyung
|
135 |
@date 2018.05.02
|
136 |
'''
|
137 |
def toXmlAsAttribute(self, parent): |
138 |
for attr in self.attrs: |
139 |
text = attr.text() |
140 |
if QRegExpValidator(QRegExp("^[0-9]+$")).validate(text, 0)[0] != QValidator.Invalid: |
141 |
parent.append(attr.toXml(self, 'OPC Tag')) |
142 |
else:
|
143 |
parent.append(attr.toXml(self, 'Description')) |