hytos / DTI_PID / DTI_PID / Shapes / QEngineeringOPCItem.py @ c3a5995f
이력 | 보기 | 이력해설 | 다운로드 (4.18 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 |
'''
|
61 |
@brief connect attribute
|
62 |
@author humkyung
|
63 |
@date 2018.05.02
|
64 |
'''
|
65 |
def connectAttribute(self, attributes, clear=True): |
66 |
from AppDocData import AppDocData, MessageType |
67 |
from EngineeringLineItem import QEngineeringLineItem |
68 |
|
69 |
try:
|
70 |
if clear:
|
71 |
self.clear_attr_and_assoc_item()
|
72 |
|
73 |
app_doc_data = AppDocData.instance() |
74 |
|
75 |
matches = [connector.connectedItem for connector in self.connectors if connector is not None and type(connector.connectedItem) is QEngineeringLineItem] |
76 |
if matches:
|
77 |
if matches[0].connectors[0].connectedItem is self: # FROM |
78 |
configs = app_doc_data.getConfigs('OPC Tag Rule', 'From Prefix') |
79 |
elif matches[0].connectors[1].connectedItem is self: # TO |
80 |
configs = app_doc_data.getConfigs('OPC Tag Rule', 'To Prefix') |
81 |
|
82 |
self.set_property('Logical', 'Process' if (matches[0].lineType == 'Primary' or matches[0].lineType == 'Secondary') else 'Instrument') # set OPC type |
83 |
|
84 |
rect = self.sceneBoundingRect()
|
85 |
for attr in attributes: |
86 |
if rect.contains(attr.center()):
|
87 |
self.add_assoc_item(attr)
|
88 |
attr.owner = self
|
89 |
|
90 |
if 'Text Item' in self._associations and self._associations['Text Item']: |
91 |
if 0 == self.angle: |
92 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[0]) # sort by x coordinate |
93 |
elif 3.14 == self.angle: |
94 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[0], reverse=True) # sort by x coordinate by descending |
95 |
elif 1.57 == self.angle: |
96 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[1], reverse=True) # sort by y coordinate |
97 |
elif 4.71 == self.angle: |
98 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[1]) # sort by y coordinate |
99 |
except Exception as ex: |
100 |
from App import App |
101 |
|
102 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
103 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
104 |
|
105 |
'''
|
106 |
@brief generate xml code for attribute
|
107 |
@author humkyung
|
108 |
@date 2018.05.02
|
109 |
'''
|
110 |
def toXmlAsAttribute(self, parent): |
111 |
for attr in self.attrs: |
112 |
text = attr.text() |
113 |
if QRegExpValidator(QRegExp("^[0-9]+$")).validate(text, 0)[0] != QValidator.Invalid: |
114 |
parent.append(attr.toXml(self, 'OPC Tag')) |
115 |
else:
|
116 |
parent.append(attr.toXml(self, 'Description')) |