개정판 18f54b2f
Merge lines which are collinear when write line to xml file
DTI_PID/DTI_PID/LineNoTracer.py | ||
---|---|---|
35 | 35 |
configs = docData.getConfigs('Line No', 'Configuration') |
36 | 36 |
|
37 | 37 |
docData.lineNos.clear() |
38 |
docData.lineNos = self.lineNos#[text for text in self.texts if text.isLineNo(delimiter, configs)] |
|
38 |
for lineNo in self.lineNos: lineNo.conns.clear() |
|
39 |
docData.lineNos = self.lineNos |
|
39 | 40 |
for lineno in docData.lineNos: |
40 | 41 |
minDist = None |
41 | 42 |
startLine = None |
DTI_PID/DTI_PID/Shapes/QEngineeringLineItem.py | ||
---|---|---|
61 | 61 |
def clone(self): |
62 | 62 |
clone = QEngineeringLineItem() |
63 | 63 |
clone._vertices = copy.deepcopy(self._vertices) |
64 |
for vertex in clone._vertices: |
|
65 |
clone._pol.append(vertex) |
|
66 |
clone.buildPath() |
|
64 | 67 |
clone.isCreated = self.isCreated |
65 | 68 |
|
66 | 69 |
return clone |
... | ... | |
106 | 109 |
return (dx,dy) |
107 | 110 |
|
108 | 111 |
''' |
109 |
@brief return angle of line |
|
112 |
@brief return angle of line in radian
|
|
110 | 113 |
@author humkyung |
111 | 114 |
@date 2018.04.22 |
112 | 115 |
''' |
... | ... | |
122 | 125 |
return math.acos(dot/length) |
123 | 126 |
|
124 | 127 |
''' |
128 |
@brief check if line is horizontal |
|
129 |
@author humkyung |
|
130 |
@date 2018.04.27 |
|
131 |
''' |
|
132 |
def isHorizontal(self): |
|
133 |
import math |
|
134 |
|
|
135 |
startPt = self.startPoint() |
|
136 |
endPt = self.endPoint() |
|
137 |
dx = endPt[0] - startPt[0] |
|
138 |
dy = endPt[1] - startPt[1] |
|
139 |
|
|
140 |
return math.fabs(dx) > math.fabs(dy) |
|
141 |
|
|
142 |
''' |
|
143 |
@brief check if line is vertical |
|
144 |
@author humkyung |
|
145 |
@date 2018.04.27 |
|
146 |
''' |
|
147 |
def isVertical(self): |
|
148 |
import math |
|
149 |
|
|
150 |
startPt = self.startPoint() |
|
151 |
endPt = self.endPoint() |
|
152 |
dx = endPt[0] - startPt[0] |
|
153 |
dy = endPt[1] - startPt[1] |
|
154 |
|
|
155 |
return math.fabs(dy) > math.fabs(dx) |
|
156 |
|
|
157 |
''' |
|
125 | 158 |
@brief get intersection point between this and given line |
126 | 159 |
@author humkyung |
127 | 160 |
@date 2018.04.21 |
DTI_PID/DTI_PID/Shapes/QEngineeringLineNoTextItem.py | ||
---|---|---|
1 | 1 |
# coding: utf-8 |
2 | 2 |
import os.path |
3 |
import sys |
|
3 | 4 |
import copy |
4 | 5 |
try: |
5 | 6 |
from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
... | ... | |
26 | 27 |
|
27 | 28 |
QEngineeringTextItem.__init__(self, parent) |
28 | 29 |
|
30 |
def getLongestTwoPoints(self, pts): |
|
31 |
import math |
|
32 |
res = [None, None] |
|
33 |
|
|
34 |
maxDistance = None |
|
35 |
for i in range(len(pts)): |
|
36 |
for j in range(i+1, len(pts)): |
|
37 |
dx = pts[i][0] - pts[j][0] |
|
38 |
dy = pts[i][1] - pts[j][1] |
|
39 |
dist = math.sqrt(dx*dx + dy*dy) |
|
40 |
if (maxDistance is None) or (maxDistance < dist): |
|
41 |
maxDistance = dist |
|
42 |
res[0] = pts[i] |
|
43 |
res[1] = pts[j] |
|
44 |
|
|
45 |
return res |
|
46 |
|
|
47 |
''' |
|
48 |
@brief generate xml code |
|
49 |
@author humkyung |
|
50 |
@date 2018.04.23 |
|
51 |
''' |
|
52 |
def toXml(self): |
|
53 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
|
54 |
from QEngineeringLineItem import QEngineeringLineItem |
|
55 |
from SymbolSvgItem import SymbolSvgItem |
|
56 |
|
|
57 |
try: |
|
58 |
docData = AppDocData.instance() |
|
59 |
configs = docData.getConfigs('Line No', 'Delimiter') |
|
60 |
delimiter = configs[0].value if 1 == len(configs) else '-' |
|
61 |
lineNoconfigs = docData.getConfigs('Line No', 'Configuration') |
|
62 |
|
|
63 |
node = Element('LINE_NO') |
|
64 |
uidNode = Element('UID') |
|
65 |
uidNode.text = str(self.uid) |
|
66 |
|
|
67 |
textNode = Element('TEXT') |
|
68 |
textNode.text = self.text() |
|
69 |
|
|
70 |
rect = self.sceneBoundingRect() |
|
71 |
locNode = Element('LOCATION') |
|
72 |
locNode.text = '{},{}'.format(rect.left(), rect.top()) |
|
73 |
|
|
74 |
widthNode = Element('WIDTH') |
|
75 |
widthNode.text = str(rect.width()) |
|
76 |
|
|
77 |
heightNode = Element('HEIGHT') |
|
78 |
heightNode.text = str(rect.height()) |
|
79 |
|
|
80 |
angleNode = Element('ANGLE') |
|
81 |
angleNode.text = str(self.angle) |
|
82 |
|
|
83 |
node.append(uidNode) |
|
84 |
node.append(textNode) |
|
85 |
node.append(locNode) |
|
86 |
node.append(widthNode) |
|
87 |
node.append(heightNode) |
|
88 |
node.append(angleNode) |
|
89 |
|
|
90 |
connectedItems = self.getConnectedItems() |
|
91 |
connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem] |
|
92 |
while len(connectedLines) > 0: |
|
93 |
line = connectedLines.pop() |
|
94 |
if line.isHorizontal(): |
|
95 |
groupItems = [item for item in connectedLines if item.isHorizontal() and (line.startPoint()[1] - item.startPoint()[1] < 1)] |
|
96 |
elif line.isVertical(): |
|
97 |
groupItems = [item for item in connectedLines if item.isVertical() and (line.startPoint()[0] - item.startPoint()[0] < 1)] |
|
98 |
|
|
99 |
pts = [] |
|
100 |
pts.append(line.startPoint()) |
|
101 |
pts.append(line.endPoint()) |
|
102 |
for item in groupItems: |
|
103 |
pts.append(item.startPoint()) |
|
104 |
pts.append(item.endPoint()) |
|
105 |
longestPoints = self.getLongestTwoPoints(pts) |
|
106 |
if 2 == len(longestPoints): |
|
107 |
tmp = QEngineeringLineItem() |
|
108 |
tmp._pol.append(QPointF(longestPoints[0][0], longestPoints[0][1])) |
|
109 |
tmp._pol.append(QPointF(longestPoints[1][0], longestPoints[1][1])) |
|
110 |
node.append(tmp.toXml()) |
|
111 |
|
|
112 |
for item in groupItems: connectedLines.remove(item) |
|
113 |
|
|
114 |
#for item in connectedLines: |
|
115 |
# node.append(item.toXml()) |
|
116 |
|
|
117 |
connectedSymbols = [item for item in connectedItems if type(item) is SymbolSvgItem] |
|
118 |
for item in connectedSymbols: |
|
119 |
node.append(item.toXml()) |
|
120 |
|
|
121 |
attrs = self.getLineNoAttributes() |
|
122 |
for key,value in attrs.items(): |
|
123 |
attrNode = Element('ATTRIBUTE') |
|
124 |
|
|
125 |
uidNode = Element('UID') |
|
126 |
uidNode.text = str(self.uid) |
|
127 |
attrNode.append(uidNode) |
|
128 |
|
|
129 |
nameNode = Element('NAME') |
|
130 |
nameNode.text = str(key) |
|
131 |
attrNode.append(nameNode) |
|
132 |
|
|
133 |
valueNode = Element('VALUE') |
|
134 |
valueNode.text = str(value) |
|
135 |
attrNode.append(valueNode) |
|
136 |
|
|
137 |
node.append(attrNode) |
|
138 |
except Exception as ex: |
|
139 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
140 |
|
|
141 |
return node |
|
142 |
|
|
29 | 143 |
def hoverEnterEvent(self, event): |
30 | 144 |
pass |
31 | 145 |
|
DTI_PID/DTI_PID/Shapes/QEngineeringTextItem.py | ||
---|---|---|
235 | 235 |
return res |
236 | 236 |
|
237 | 237 |
''' |
238 |
@brief generate xml code |
|
239 |
@author humkyung |
|
240 |
@date 2018.04.23 |
|
238 |
@brief generate xml code |
|
239 |
@author humkyung |
|
240 |
@date 2018.04.23 |
|
241 |
@history humkyung 2018.04.27 move to QEngineeringLineNoTextItem |
|
241 | 242 |
''' |
242 | 243 |
def toXml(self): |
243 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
|
244 |
from QEngineeringLineItem import QEngineeringLineItem |
|
245 |
from SymbolSvgItem import SymbolSvgItem |
|
246 |
|
|
247 |
try: |
|
248 |
docData = AppDocData.instance() |
|
249 |
configs = docData.getConfigs('Line No', 'Delimiter') |
|
250 |
delimiter = configs[0].value if 1 == len(configs) else '-' |
|
251 |
lineNoconfigs = docData.getConfigs('Line No', 'Configuration') |
|
252 |
|
|
253 |
if self.isLineNo(delimiter, lineNoconfigs): |
|
254 |
node = Element('LINE_NO') |
|
255 |
uidNode = Element('UID') |
|
256 |
uidNode.text = str(self.uid) |
|
257 |
|
|
258 |
textNode = Element('TEXT') |
|
259 |
textNode.text = self.text() |
|
260 |
|
|
261 |
rect = self.sceneBoundingRect() |
|
262 |
locNode = Element('LOCATION') |
|
263 |
locNode.text = '{},{}'.format(rect.left(), rect.top()) |
|
264 |
|
|
265 |
widthNode = Element('WIDTH') |
|
266 |
widthNode.text = str(rect.width()) |
|
267 |
|
|
268 |
heightNode = Element('HEIGHT') |
|
269 |
heightNode.text = str(rect.height()) |
|
270 |
|
|
271 |
angleNode = Element('ANGLE') |
|
272 |
angleNode.text = str(self.angle) |
|
273 |
|
|
274 |
node.append(uidNode) |
|
275 |
node.append(textNode) |
|
276 |
node.append(locNode) |
|
277 |
node.append(widthNode) |
|
278 |
node.append(heightNode) |
|
279 |
node.append(angleNode) |
|
280 |
|
|
281 |
connectedItems = self.getConnectedItems() |
|
282 |
connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem] |
|
283 |
for item in connectedLines: |
|
284 |
node.append(item.toXml()) |
|
285 |
|
|
286 |
connectedSymbols = [item for item in connectedItems if type(item) is SymbolSvgItem] |
|
287 |
for item in connectedSymbols: |
|
288 |
node.append(item.toXml()) |
|
289 |
|
|
290 |
attrs = self.getLineNoAttributes() |
|
291 |
for key,value in attrs.items(): |
|
292 |
attrNode = Element('ATTRIBUTE') |
|
293 |
|
|
294 |
uidNode = Element('UID') |
|
295 |
uidNode.text = str(self.uid) |
|
296 |
attrNode.append(uidNode) |
|
297 |
|
|
298 |
nameNode = Element('NAME') |
|
299 |
nameNode.text = str(key) |
|
300 |
attrNode.append(nameNode) |
|
301 |
|
|
302 |
valueNode = Element('VALUE') |
|
303 |
valueNode.text = str(value) |
|
304 |
attrNode.append(valueNode) |
|
305 |
|
|
306 |
node.append(attrNode) |
|
307 |
except Exception as ex: |
|
308 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
309 |
|
|
310 |
return node |
|
244 |
pass |
DTI_PID/DTI_PID/Shapes/QGraphicsPolylineItem.py | ||
---|---|---|
59 | 59 |
self._path = QPainterPath() |
60 | 60 |
self._path.addPolygon(self._pol) |
61 | 61 |
self.setPath(self._path) |
62 |
self.isCreated = True |
|
62 | 63 |
|
63 | 64 |
''' |
64 | 65 |
@brief return start point |
... | ... | |
76 | 77 |
''' |
77 | 78 |
def endPoint(self): |
78 | 79 |
at = self._pol.at(self._pol.count() - 1) |
79 |
return (at.x(), at.y()) |
|
80 |
return (at.x(), at.y()) |
|
81 |
|
|
82 |
''' |
|
83 |
@brief paint |
|
84 |
''' |
|
85 |
def paint(self, painter, options=None, widget=None): |
|
86 |
if self.isCreated: |
|
87 |
QGraphicsPathItem.paint(self, painter, options, widget) |
|
88 |
elif len(self._vertices) > 0: |
|
89 |
pen = QPen(Qt.blue, 20, Qt.SolidLine) |
|
90 |
painter.setPen(pen) |
|
91 |
for i in range(len(self._vertices)-1): |
|
92 |
painter.drawLine(self._vertices[i].x(), self._vertices[i].y(), self._vertices[i+1].x(), self._vertices[i+1].y()) |
|
93 |
if self._pt is not None: |
|
94 |
painter.drawLine(self._vertices[len(self._vertices)-1].x(), self._vertices[len(self._vertices)-1].y(), self._pt.x(), self._pt.y()) |
|
95 |
|
|
96 |
''' |
|
97 |
if self.isSelected: |
|
98 |
rect = self.boundingRect() |
|
99 |
painter.drawRect(rect.left(), rect.top(), rect.width(), rect.height()) |
|
100 |
''' |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
28 | 28 |
self.name = '' |
29 | 29 |
self.type = '' |
30 | 30 |
self.angle = 0 |
31 |
self.origin = None |
|
31 | 32 |
self.loc = None |
32 | 33 |
self.size = None |
33 | 34 |
self.conns = [] |
... | ... | |
132 | 133 |
@author humkyung |
133 | 134 |
@date 2018.04.23 |
134 | 135 |
@history humkyung 2018.04.25 add angle xml node |
136 |
humkyung 2018.04.27 add originalpoint xml node |
|
135 | 137 |
''' |
136 | 138 |
def toXml(self): |
137 | 139 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
... | ... | |
140 | 142 |
node = Element('SYMBOL') |
141 | 143 |
uidNode = Element('UID') |
142 | 144 |
uidNode.text = str(self.uid) |
145 |
node.append(uidNode) |
|
143 | 146 |
|
144 | 147 |
nameNode = Element('NAME') |
145 | 148 |
nameNode.text = self.name |
149 |
node.append(nameNode) |
|
150 |
|
|
151 |
originNode = Element('ORIGINALPOINT') |
|
152 |
originNode.text = '{},{}'.format(self.origin[0], self.origin[1]) |
|
153 |
node.append(originNode) |
|
146 | 154 |
|
147 | 155 |
rect = self.sceneBoundingRect() |
148 | 156 |
locNode = Element('LOCATION') |
149 | 157 |
locNode.text = '{},{}'.format(rect.left(), rect.top()) |
158 |
node.append(locNode) |
|
150 | 159 |
|
151 | 160 |
sizeNode = Element('SIZE') |
152 | 161 |
sizeNode.text = '{},{}'.format(rect.width(), rect.height()) |
162 |
node.append(sizeNode) |
|
153 | 163 |
|
154 | 164 |
angleNode = Element('ANGLE') |
155 | 165 |
angleNode.text = str(self.angle) |
156 |
|
|
157 |
node.append(uidNode) |
|
158 |
node.append(nameNode) |
|
159 |
node.append(locNode) |
|
160 |
node.append(sizeNode) |
|
161 | 166 |
node.append(angleNode) |
162 | 167 |
except Exception as ex: |
163 | 168 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
내보내기 Unified diff