개정판 ea59dc23
QEngineeringRunItem 수정 - toler 수정(1 -> 5) / math.fabs() 추가 / LongestLine 의 좌표 조정
DTI_PID/DTI_PID/Shapes/QEngineeringRunItem.py | ||
---|---|---|
66 | 66 |
@brief write to xml |
67 | 67 |
@author humkyung |
68 | 68 |
@date 2018.05.16 |
69 |
@history 2018.05.24 Jeongwoo Add math.fabs() on sublist's if-statement |
|
70 |
Change toler(1 → 5) and Modify Longest Line's coords // Make comments Test Code |
|
69 | 71 |
''' |
70 | 72 |
def toXml(self): |
71 | 73 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
72 | 74 |
from QEngineeringLineItem import QEngineeringLineItem |
75 |
import math |
|
73 | 76 |
from SymbolSvgItem import SymbolSvgItem |
77 |
#from AppDocData import AppDocData |
|
78 |
#import numpy as np |
|
79 |
#import cv2 |
|
80 |
#import matplotlib.pyplot as plt |
|
74 | 81 |
|
75 | 82 |
try: |
83 |
#img = np.array(AppDocData.instance().getCurrentPidSource().getPyImageOnRect()) |
|
84 |
|
|
76 | 85 |
node = Element('RUN') |
77 | 86 |
|
78 | 87 |
connectedLines = [item for item in self.items if type(item) is QEngineeringLineItem] |
... | ... | |
81 | 90 |
while len(connectedLines) > 0: |
82 | 91 |
line = connectedLines.pop() |
83 | 92 |
if line.isHorizontal(): |
84 |
groupItems = [item for item in connectedLines if item.isHorizontal() and (line.startPoint()[1] - item.startPoint()[1] < 1)]
|
|
93 |
groupItems = [item for item in connectedLines if item.isHorizontal() and (math.fabs(line.startPoint()[1] - item.startPoint()[1]) < 5)]
|
|
85 | 94 |
elif line.isVertical(): |
86 |
groupItems = [item for item in connectedLines if item.isVertical() and (line.startPoint()[0] - item.startPoint()[0] < 1)]
|
|
95 |
groupItems = [item for item in connectedLines if item.isVertical() and (math.fabs(line.startPoint()[0] - item.startPoint()[0]) < 5)]
|
|
87 | 96 |
|
88 | 97 |
pts = [] |
89 | 98 |
pts.append(line.startPoint()) |
... | ... | |
94 | 103 |
longestPoints = self.getLongestTwoPoints(pts) |
95 | 104 |
if 2 == len(longestPoints): |
96 | 105 |
tmp = QEngineeringLineItem() |
97 |
tmp._pol.append(QPointF(longestPoints[0][0], longestPoints[0][1])) |
|
98 |
tmp._pol.append(QPointF(longestPoints[1][0], longestPoints[1][1])) |
|
106 |
if line.isHorizontal(): |
|
107 |
adjustY = (longestPoints[0][1] + longestPoints[1][1]) / 2 |
|
108 |
tmp._pol.append(QPointF(longestPoints[0][0], adjustY)) |
|
109 |
tmp._pol.append(QPointF(longestPoints[1][0], adjustY)) |
|
110 |
#cv2.line(img, (int(longestPoints[0][0]), int(adjustY)), (int(longestPoints[1][0]), int(adjustY)), (0, 0, 255), 1) |
|
111 |
elif line.isVertical(): |
|
112 |
adjustX = (longestPoints[0][0] + longestPoints[1][0]) / 2 |
|
113 |
tmp._pol.append(QPointF(adjustX, longestPoints[0][1])) |
|
114 |
tmp._pol.append(QPointF(adjustX, longestPoints[1][1])) |
|
115 |
#cv2.line(img, (int(adjustX), int(longestPoints[0][1])), (int(adjustX), int(longestPoints[1][1])), (0, 0, 255), 1) |
|
99 | 116 |
node.append(tmp.toXml()) |
100 | 117 |
|
101 | 118 |
for item in groupItems: connectedLines.remove(item) |
... | ... | |
112 | 129 |
for item in connectedSymbols: |
113 | 130 |
item.toXmlAsAttribute(node) |
114 | 131 |
|
132 |
#img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
|
133 |
#plt.imshow(img) |
|
134 |
#plt.show() |
|
135 |
|
|
115 | 136 |
except Exception as ex: |
116 | 137 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
117 | 138 |
|
내보내기 Unified diff