hytos / DTI_PID / DTI_PID / Shapes / QEngineeringLineNoTextItem.py @ d1566ccd
이력 | 보기 | 이력해설 | 다운로드 (7.99 KB)
1 |
# coding: utf-8
|
---|---|
2 |
import os.path |
3 |
import sys |
4 |
import copy |
5 |
try:
|
6 |
from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
7 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont |
8 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, QGraphicsTextItem |
9 |
except ImportError: |
10 |
try:
|
11 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
12 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QFont |
13 |
except ImportError: |
14 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
15 | |
16 |
from QGraphicsPolylineItem import QGraphicsPolylineItem |
17 |
from QGraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
18 |
import QOcrResultDialog |
19 |
from AppDocData import AppDocData |
20 |
from QEngineeringTextItem import QEngineeringTextItem |
21 | |
22 |
class QEngineeringLineNoTextItem(QEngineeringTextItem): |
23 | |
24 |
'''
|
25 |
@history 18.05.14 Jeongwoo Add variable self.runs
|
26 |
humkyung 2018.07.09 add stream no
|
27 |
'''
|
28 |
def __init__(self, parent=None): |
29 |
import uuid |
30 |
|
31 |
QEngineeringTextItem.__init__(self, parent)
|
32 |
|
33 |
self._runs = []
|
34 |
self._streamNo = None |
35 | |
36 |
'''
|
37 |
@brief getter of runs
|
38 |
@author humkyung
|
39 |
@date 2018.05.11
|
40 |
'''
|
41 |
@property
|
42 |
def runs(self): |
43 |
return self._runs |
44 | |
45 |
'''
|
46 |
@brief setter of runs
|
47 |
@author humkyung
|
48 |
@date 2018.05.11
|
49 |
'''
|
50 |
@runs.setter
|
51 |
def runs(self, value): |
52 |
self._runs = value
|
53 |
|
54 |
'''
|
55 |
@brief getter of stream no
|
56 |
@author humkyung
|
57 |
@date 2018.07.09
|
58 |
'''
|
59 |
@property
|
60 |
def streamNo(self): |
61 |
return self._streamNo |
62 | |
63 |
'''
|
64 |
@brief setter of stream no
|
65 |
@author humkyung
|
66 |
@date 2018.07.09
|
67 |
'''
|
68 |
@streamNo.setter
|
69 |
def streamNo(self, value): |
70 |
self._streamNo = value
|
71 | |
72 |
def getLongestTwoPoints(self, pts): |
73 |
import math |
74 |
res = [None, None] |
75 | |
76 |
maxDistance = None
|
77 |
for i in range(len(pts)): |
78 |
for j in range(i+1, len(pts)): |
79 |
dx = pts[i][0] - pts[j][0] |
80 |
dy = pts[i][1] - pts[j][1] |
81 |
dist = math.sqrt(dx*dx + dy*dy) |
82 |
if (maxDistance is None) or (maxDistance < dist): |
83 |
maxDistance = dist |
84 |
res[0] = pts[i]
|
85 |
res[1] = pts[j]
|
86 |
|
87 |
return res
|
88 |
|
89 |
'''
|
90 |
@brief get line no attributes
|
91 |
@author humkyung
|
92 |
@date 2018.04.24
|
93 |
@history humkyung 2018.05.09 evaluate string for Tag Seq No
|
94 |
kyouho 2018.07.06 add using TextItemFactory.isLineNo method
|
95 |
'''
|
96 |
def getLineNoAttributes(self): |
97 |
res = [] |
98 | |
99 |
try:
|
100 |
docData = AppDocData.instance() |
101 |
configs = docData.getConfigs('Line No', 'Delimiter') |
102 |
delimiter = configs[0].value if 1 == len(configs) else '-' |
103 |
lineNoconfigs = docData.getConfigs('Line No', 'Configuration') |
104 |
#
|
105 |
linePropertyData = {} |
106 |
linePropertyData['NominalDiameter'] = docData.getNomialPipeSizeData(True) |
107 |
linePropertyData['FluidCode'] = docData.getCodeTable('FluidCode', True) |
108 |
linePropertyData['UnitNumber'] = docData.getCodeTable('UnitNumber', True) |
109 |
linePropertyData['PnIDNumber'] = docData.getCodeTable('PnIDNumber', True) |
110 |
linePropertyData['PipingMaterialsClass'] = docData.getCodeTable('PipingMaterialsClass', True) |
111 |
linePropertyData['InsulationPurpose'] = docData.getCodeTable('InsulationPurpose', True) |
112 |
#
|
113 |
configs = docData.getConfigs('Line No Tag Rule', 'Tag Seq No') |
114 |
tagSeqNoPattern = configs[0].value if 1 == len(configs) else None |
115 | |
116 |
from TextItemFactory import TextItemFactory |
117 |
item = TextItemFactory.instance().isLineNo(self.text(), delimiter, lineNoconfigs, linePropertyData, tagSeqNoPattern)
|
118 | |
119 |
if item[0]: |
120 |
result = item[1]
|
121 |
configs = lineNoconfigs[0].value.split(self.delimiter) |
122 |
for i in range(len(configs)): |
123 |
if configs[i] == delimiter:
|
124 |
continue
|
125 |
res.append((configs[i], result[i])) |
126 | |
127 |
res.append(('Stream No', self.streamNo)) |
128 |
except Exception as ex: |
129 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
130 |
|
131 |
return res
|
132 | |
133 |
'''
|
134 |
@brief generate xml code
|
135 |
@author humkyung
|
136 |
@date 2018.04.23
|
137 |
@history humkyung 2018.05.02 write symbol's attribute
|
138 |
humkyung 2018.05.16 write run information to xml
|
139 |
'''
|
140 |
def toXml(self): |
141 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
142 |
from QEngineeringLineItem import QEngineeringLineItem |
143 |
from SymbolSvgItem import SymbolSvgItem |
144 | |
145 |
try:
|
146 |
docData = AppDocData.instance() |
147 |
configs = docData.getConfigs('Line No', 'Delimiter') |
148 |
delimiter = configs[0].value if 1 == len(configs) else '-' |
149 |
lineNoconfigs = docData.getConfigs('Line No', 'Configuration') |
150 | |
151 |
node = Element('LINE_NO')
|
152 |
uidNode = Element('UID')
|
153 |
uidNode.text = str(self.uid) |
154 |
node.append(uidNode) |
155 | |
156 |
textNode = Element('TEXT')
|
157 |
textNode.text = self.text()
|
158 |
node.append(textNode) |
159 | |
160 |
rect = self.sceneBoundingRect()
|
161 |
locNode = Element('LOCATION')
|
162 |
locNode.text = '{},{}'.format(rect.left(), rect.top())
|
163 |
node.append(locNode) |
164 | |
165 |
widthNode = Element('WIDTH')
|
166 |
widthNode.text = str(rect.width())
|
167 |
node.append(widthNode) |
168 | |
169 |
heightNode = Element('HEIGHT')
|
170 |
heightNode.text = str(rect.height())
|
171 |
node.append(heightNode) |
172 | |
173 |
angleNode = Element('ANGLE')
|
174 |
angleNode.text = str(self.angle) |
175 |
node.append(angleNode) |
176 | |
177 |
for run in self.runs: |
178 |
node.append(run.toXml()) |
179 | |
180 |
attrs = self.getLineNoAttributes()
|
181 |
for key,value in attrs.items(): |
182 |
attrNode = Element('ATTRIBUTE')
|
183 | |
184 |
uidNode = Element('UID')
|
185 |
uidNode.text = str(self.uid) |
186 |
attrNode.append(uidNode) |
187 | |
188 |
nameNode = Element('NAME')
|
189 |
nameNode.text = str(key)
|
190 |
attrNode.append(nameNode) |
191 | |
192 |
valueNode = Element('VALUE')
|
193 |
valueNode.text = str(value)
|
194 |
attrNode.append(valueNode) |
195 | |
196 |
node.append(attrNode) |
197 |
except Exception as ex: |
198 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
199 | |
200 |
return node
|
201 | |
202 |
def hoverEnterEvent(self, event): |
203 |
pass
|
204 | |
205 |
def hoverLeaveEvent(self, event): |
206 |
pass
|
207 | |
208 |
def hoverMoveEvent(self, event): |
209 |
pass
|
210 |
|
211 |
'''
|
212 |
@Override (QEngineeringTextItem)
|
213 |
@brief get connected items
|
214 |
@author Jeongwoo
|
215 |
@date 2018.05.15
|
216 |
'''
|
217 |
def getConnectedItems(self): |
218 |
visited = [] |
219 | |
220 |
try:
|
221 |
if self.runs is not None: |
222 |
for run in self.runs: |
223 |
items = run.items |
224 |
if items is not None: |
225 |
for item in items: |
226 |
pool = [] |
227 |
pool.append(item) |
228 |
while len(pool) > 0: |
229 |
it = pool.pop() |
230 |
visited.append(it) |
231 |
for conn in it.conns: |
232 |
if (conn is not None) and (conn not in visited): pool.append(conn) |
233 |
except Exception as ex: |
234 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
235 | |
236 |
return visited
|